← Back
ExercisesBy topicItalian

Sistemi operativi 1 Thread e programmazione concorrente

Study material for Architettura dei Calcolatori e Sistemi Operativi, shared by the Studwiz community and reviewed by moderators.

Architettura dei Calcolatori e Sistemi OperativiBy topic

Document information

What's included in this study material

Study material for Architettura dei Calcolatori e Sistemi Operativi, shared by the Studwiz community and reviewed by moderators.

Import quality: text was extracted directly from the original document.

Extracted content from the document

Representative passages recognised in different parts of the material. The full extracted text remains available to search, while this compact preview makes the page easier to read.

Page 1

Temi AXO su thread e programmazione concorrente pp. 1 / 25 RACCOLTA DI ESERCIZI SU THREAD E PROGRAMMAZIONE CONCORRENTE I docenti di AXO A.A. 2015-16 Temi AXO su thread e programmazione concorrente pp. 2 / 25 esercizio su thread e parallelismo – mercoledì 21 novembre 2012 Si consideri il programma C seguente (gli “#include” sono omessi): pthread_mutex_t law = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t order = PTHREAD_MUTEX_INITIALIZER; sem_t mess; int global = 0; void  one (void  arg) { int local = 0; pthread_mutex_lock (&law); sem_post (&mess); local = 1; /  statement A / pthread_mutex_unlock (&law); global = 1; pthread_mutex_lock (&order); local = 3; /  statement B / pthread_mutex_unlock (&order); return (void ) global; } / end one / void  two (void  arg) { int local = 0; pthread_mutex_lock (&order); global = 2; pthread_mutex_lock (&law); sem_wait (&mess); /  statement C / local = (int) arg; pthread_mutex_unlock (&law); pthread_mutex_unlock (&order); return NULL; } / end two / void main ( ) { pthread_t th_1, th_2; sem_init (&mess, 0, 0); pthread_create (&th_2, NULL, two, (void ) 2); pthread_create (&th_1, NULL, one, NULL); pthread_join (th_1, &global); /  statement D / pthread_join (th_2, NULL); return;  / end main / Temi AXO su thread e programmazione concorrente pp. 3 / 25 Si completi la tabella qui sotto indicando lo stato di esistenza della variabile locale nell’istante di tempo specificato da ciascuna condizione, così: se la variabile esiste, si scriva ESISTE; se non esiste, si scriva NON ESISTE; e se può essere esistente o inesistente, si scriva PUÒ ESISTERE. Ogni casella della tabella va riempita in uno dei tre modi (non va lasciata vuota). Si badi bene alla colonna condizione: con subito dopo statement X si chiede lo stato che la variabile…

Preview

First page of the document.

First page: Sistemi operativi 1 Thread e programmazione concorrente