Ignore:
Timestamp:
Apr 21, 2012, 12:24:25 PM (12 years ago)
Author:
Mattia Monga
Message:

Aggiornati 2012

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/threads-isolated.c

    r2 r15  
    1010int run(void* s)
    1111{
    12         int* shared = (int*)s; /* alias per comodita` */
     12        int* shared = (int*)s; // alias per comodit\`a
    1313        while (shared[0] < 10) {
    1414                sleep(1);
     
    2828 
    2929        int shared[2] = {0 , 0};
    30 
    3130        /* int clone(int (*fn)(void *),
    3231         *           void *child_stack,
     
    4039                  malloc(4096)+4096,  /* lo stack del nuovo processo
    4140                                       *  (cresce verso il basso!) */
    42                   SIGCHLD, /* in questo caso la clone e` analoga alla fork */
     41                  SIGCHLD, // in questo caso la clone \`e analoga alla fork
    4342                  shared) < 0){
    44                 perror("Errore nella creazione");
    45                 exit(1);
     43                perror("Errore nella creazione");exit(1);
     44        }
     45        if (clone(run, malloc(4096)+4096,  SIGCHLD, shared) < 0){
     46                perror("Errore nella creazione");exit(1);
    4647        }
    4748
    48         if (clone(run, malloc(4096)+4096,  SIGCHLD, shared) < 0){
    49                 perror("Errore nella creazione");
    50                 exit(1);
    51         }
     49        /* Isolati: ciascuno dei figli esegue 10 volte. */
     50        // Per il padre shared[0] \`e \textbf{sempre} 0 */
    5251
    53         /* Isolati: ciascuno dei figli esegue 10 volte. Per il padre
    54          * shared[0] e` sempre 0 */
    55 
    56         while(1) {
     52        while(shared[0] == 0) {
    5753                sleep(1);
    5854                printf("Processo padre. s = %d\n", shared[0]);
Note: See TracChangeset for help on using the changeset viewer.