Changeset 15


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

Aggiornati 2012

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Makefile

    r2 r15  
    1 CFLAGS=-m32
    2 LDFLAGS=-m32
     1TARGET_ARCH=-m32
     2ASM=nasm
    33
    44mioboot: mioboot.asm
    5         nasm -l $@.lst -o $@ $<
     5        $(ASM) -l $@.lst -o $@ $<
    66
    77mioboot-nobios: mioboot-nobios.asm
    8         nasm -l $@.lst -o $@ $<
     8        $(ASM) -l $@.lst -o $@ $<
    99
    1010mioboot-nobios-simple: mioboot-nobios-simple.asm
    11         nasm -l $@.lst -o $@ $<
     11        $(ASM) -l $@.lst -o $@ $<
    1212
    1313
    14 esercizio: esercizio.asm
    15         nasm -f elf $<
    16         gcc -o $@ esercizio.o
     14esercizio.o: esercizio.asm
     15        $(ASM) -felf $<
     16
     17esercizio: esercizio.o
     18
     19pthreads-pc : LDFLAGS=-lrt
    1720
    1821pthreads-pc: pthreads-pc.c
    19         cc -pthread pthreads-pc.c -o pthreads-pc
    2022
    2123fork-pc: fork-pc.c
    22         cc fork-pc.c -o fork-pc
    2324
    24 tsl: tsl.asm
    25         nasm -felf tsl.asm
    26         gcc tsl.o -o tsl
     25tsl.o: tsl.asm
     26        $(ASM) -felf tsl.asm
     27
     28tsl: tsl.o
    2729
    2830enter.o: enter.asm
    29         nasm -felf enter.asm
     31        $(ASM) -felf enter.asm
    3032
    3133threads-tsl: threads-tsl.o enter.o
  • 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]);
  • trunk/threads-peterson.c

    r2 r15  
    2626int run(const int p, void* s)
    2727{
    28         int* shared = (int*)s; /* alias per comodita` */
    29         while (enter_section(p, &shared[1], &shared[2]),
    30                shared[0] < 10) {
     28        int* shared = (int*)s; // alias per comodit\`a
     29        while (enter_section(p, &shared[1], &shared[2]), shared[0] < 10) {
    3130                sleep(1);
    3231                printf("Processo figlio (%d). s = %d\n",
     
    3736                }
    3837                shared[0] += 1;
    39                 leave_section(p, &shared[2]);
     38                leave_section(p, &shared[2]); 
    4039        }
     40        leave_section(p, &shared[2]);// il test nel while \`e dopo enter\_section
     41
    4142        return 0;
    4243}
     
    6162                  malloc(4096)+4096,  /* lo stack del nuovo processo
    6263                                       *  (cresce verso il basso!) */
    63                   CLONE_VM | SIGCHLD, /* la (virtual) memory e` condivisa */
     64                  CLONE_VM | SIGCHLD, /* la (virtual) memory \`e condivisa */
    6465                  shared) < 0){
    6566                perror("Errore nella creazione");
     
    7374
    7475        /* Memoria condivisa: i due figli nell'insieme eseguono 10 o
    75          * 11 volte: e` possibile una corsa critica. Il padre
     76         * 11 volte con possibili corse critiche. Il padre
    7677         * condivide shared[0] con i figli */
    7778
  • trunk/threads-shared.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                   CLONE_VM | SIGCHLD, /* la (virtual) memory e` condivisa */
     41                  CLONE_VM | SIGCHLD, // (virtual) memory condivisa
    4342                  shared) < 0){
    44                 perror("Errore nella creazione");
    45                 exit(1);
     43                perror("Errore nella creazione");exit(1);
    4644        }
    4745
    4846        if (clone(run, malloc(4096)+4096,  CLONE_VM | SIGCHLD, shared) < 0){
    49                 perror("Errore nella creazione");
    50                 exit(1);
     47                perror("Errore nella creazione");exit(1);
    5148        }
    5249
    5350        /* Memoria condivisa: i due figli nell'insieme eseguono 10 o
    54          * 11 volte: e` possibile una corsa critica. Il padre
     51         * 11 volte: \`e possibile una corsa critica. Il padre
    5552         * condivide shared[0] con i figli */
    5653
    57         while(1) {
     54        while(shared[0] < 10) {
    5855                sleep(1);
    5956                printf("Processo padre. s = %d\n", shared[0]);
  • 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
  • trunk/tsl.asm

    r2 r15  
    77        call stampa
    88        lock bts dword [x], 0
    9         jc salta                ; gia` settato
     9        jc salta                ; gi\`a settato
    1010        call stampa
    1111salta:  lock bts dword [x], 0
Note: See TracChangeset for help on using the changeset viewer.