Changes between Version 11 and Version 12 of AS6-TME-B7
- Timestamp:
- Apr 11, 2022, 8:35:22 PM (2 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
AS6-TME-B7
v11 v12 197 197 { 198 198 struct arg_s * a = arg; 199 while (1) {// faire toujours200 fprintf (1, " %s\n", a->message); // afficher un message201 DELAY ( a->delay); // calcul (il faudrait un random)202 thread_barrier_wait (&barrier); // attendre l'autre instance199 for (int i=0;1;i++) { // faire toujours 200 fprintf (1, "[%d] %s\n", i, a->message); // afficher un message 201 DELAY ((a->delay) * (1 + rand()%2)); // delay aléatoire 202 thread_barrier_wait (&barrier); // attendre les autres 203 203 }; 204 204 } … … 206 206 int main (void) 207 207 { 208 thread_barrier_init (&barrier, 2); // Créer une barrière pour 2209 210 a0.delay = 500000; // args premier thread208 thread_barrier_init (&barrier, 2); // Créer une barrière pour 2 209 210 a0.delay = 500000; // args premier thread 211 211 a0.message = "bonjour"; 212 212 213 a1.delay = 2000000; // args deuxième thread213 a1.delay = 2000000; // args deuxième thread 214 214 a1.message = "salut"; 215 215 216 thread_create (&t0, t0_fun, &a0); // démarrer premier thread217 thread_create (&t0, t0_fun, &a1); // démarrer deuxieme thread218 219 for (int i = 0;i<3; i++) { // main() bosse de son coté220 fprintf (0, "[%d] app is alive (%d)\n", clock(), i);221 DELAY(100000); 216 thread_create (&t0, t0_fun, &a0); // démarrer premier thread 217 thread_create (&t0, t0_fun, &a1); // démarrer deuxième thread 218 219 for (int i=0;1;i++) { 220 fprintf (0, "[%d] main alive\n", i); // message 221 DELAY(100000); // delay 222 222 } 223 223 224 void * trash; 225 thread_join (t1, &trash); 226 thread_join (t0, &trash); 227 return 0; 224 void * trash; // attendre la fin mais 225 thread_join (t1, &trash); // on jette le résultat 226 thread_join (t0, &trash); // et on arrivera jamais 227 return 0; // ici en réalité 228 228 } 229 229 }}}