Changeset 15 for trunk/threads-isolated.c
- Timestamp:
- Apr 21, 2012, 12:24:25 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/threads-isolated.c
r2 r15 10 10 int run(void* s) 11 11 { 12 int* shared = (int*)s; / * alias per comodita` */12 int* shared = (int*)s; // alias per comodit\`a 13 13 while (shared[0] < 10) { 14 14 sleep(1); … … 28 28 29 29 int shared[2] = {0 , 0}; 30 31 30 /* int clone(int (*fn)(void *), 32 31 * void *child_stack, … … 40 39 malloc(4096)+4096, /* lo stack del nuovo processo 41 40 * (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 43 42 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); 46 47 } 47 48 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 */ 52 51 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) { 57 53 sleep(1); 58 54 printf("Processo padre. s = %d\n", shared[0]);
Note:
See TracChangeset
for help on using the changeset viewer.