Changes between Version 11 and Version 12 of AS6-TME-B7


Ignore:
Timestamp:
Apr 11, 2022, 8:35:22 PM (2 years ago)
Author:
franck
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • AS6-TME-B7

    v11 v12  
    197197{
    198198    struct arg_s * a = arg;
    199     while (1) {                           // faire toujours
    200         fprintf (1, "%s\n", a->message);  //   afficher un message
    201         DELAY (a->delay);                 //   calcul (il faudrait un random)
    202         thread_barrier_wait (&barrier);   //   attendre l'autre instance
     199    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
    203203    };
    204204}
     
    206206int main (void)
    207207{
    208     thread_barrier_init (&barrier, 2);    // Créer une barrière pour 2
    209 
    210     a0.delay = 500000;                    // args premier thread
     208    thread_barrier_init (&barrier, 2);       // Créer une barrière pour 2
     209
     210    a0.delay = 500000;                       // args premier thread
    211211    a0.message = "bonjour";
    212212
    213     a1.delay = 2000000;                   // args deuxième thread
     213    a1.delay = 2000000;                      // args deuxième thread
    214214    a1.message = "salut";
    215215
    216     thread_create (&t0, t0_fun, &a0);     // démarrer premier thread
    217     thread_create (&t0, t0_fun, &a1);     // démarrer deuxieme thread
    218 
    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
    222222    }
    223223
    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é
    228228}
    229229}}}