Changeset 15 for trunk/threads-tsl.c


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-tsl.c

    r2 r15  
    1010
    1111void enter_section(int *s); /* in enter.asm */
     12void leave_section(int *s){ *s = 0; }
    1213
    13 void leave_section(int *s){
    14         *s = 0;
    15 }
    16 
    17 int run(const int p, void* s)
    18 {
    19         int* shared = (int*)s; /* alias per comodita` */
    20         while (enter_section(&shared[1]),
    21                shared[0] < 10) {
    22                 sleep(100);
     14int run(const int p, void* s){
     15        int* shared = (int*)s; // alias per comodit\`a
     16        while (enter_section(&shared[1]), shared[0] < 10) {
     17                sleep(1);
    2318                printf("Processo figlio (%d). s = %d\n",
    2419                       getpid(), shared[0]);
     
    3126                sched_yield();
    3227        }
     28        leave_section(&shared[1]); // il test nel while \`e dopo enter\_section
    3329        return 0;
    3430}
     
    5349                  malloc(4096)+4096,  /* lo stack del nuovo processo
    5450                                       *  (cresce verso il basso!) */
    55                   CLONE_VM | SIGCHLD, /* la (virtual) memory e` condivisa */
     51                  CLONE_VM | SIGCHLD, /* la (virtual) memory \`e condivisa */
    5652                  shared) < 0){
    5753                perror("Errore nella creazione");
     
    6561
    6662        /* Memoria condivisa: i due figli nell'insieme eseguono 10 o
    67          * 11 volte: e` possibile una corsa critica. Il padre
     63         * 11 volte: \`e possibile una corsa critica. Il padre
    6864         * condivide shared[0] con i figli */
    6965
Note: See TracChangeset for help on using the changeset viewer.