Changeset 15 for trunk/threads-tsl.c
- Timestamp:
 - Apr 21, 2012, 12:24:25 PM (14 years ago)
 - File:
 - 
      
- 1 edited
 
- 
          
  trunk/threads-tsl.c (modified) (4 diffs)
 
 
Legend:
- Unmodified
 - Added
 - Removed
 
- 
      
trunk/threads-tsl.c
r2 r15 10 10 11 11 void enter_section(int *s); /* in enter.asm */ 12 void leave_section(int *s){ *s = 0; } 12 13 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); 14 int 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); 23 18 printf("Processo figlio (%d). s = %d\n", 24 19 getpid(), shared[0]); … … 31 26 sched_yield(); 32 27 } 28 leave_section(&shared[1]); // il test nel while \`e dopo enter\_section 33 29 return 0; 34 30 } … … 53 49 malloc(4096)+4096, /* lo stack del nuovo processo 54 50 * (cresce verso il basso!) */ 55 CLONE_VM | SIGCHLD, /* la (virtual) memory e`condivisa */51 CLONE_VM | SIGCHLD, /* la (virtual) memory \`e condivisa */ 56 52 shared) < 0){ 57 53 perror("Errore nella creazione"); … … 65 61 66 62 /* Memoria condivisa: i due figli nell'insieme eseguono 10 o 67 * 11 volte: e`possibile una corsa critica. Il padre63 * 11 volte: \`e possibile una corsa critica. Il padre 68 64 * condivide shared[0] con i figli */ 69 65  
  Note:
 See   TracChangeset
 for help on using the changeset viewer.