If a thread holds a mutex lock then the thread prevents the OS from context switching to another thread.
Blog
Consider the following two pieces of code. 6 int Inser…
Consider the following two pieces of code. 6 int Insert(list_t *L, int k) {7 node_t *n = malloc(8 sizeof(node_t));9 if (n == NULL) {10 perror(“malloc”);11 return -1;12 }13 new->key = k;14 pthread_mutex_lock(&L->lock);15 new->next = L->head;16 L->head = new;17 pthread_mutex_unlock(&L->lock);18 return 0; // success19 } 6 int Insert(list_t *L, int k) {7 pthread_mutex_lock(&L->lock);8 node_t *new = malloc(9 sizeof(node_t));10 if (new == NULL) {11 perror(“malloc”);12 pthread_mutex_unlock(13 &L->lock);14 return -1; // fail15 }16 new->key = k;17 new->next = L->head;18 L->head = new;19 pthread_mutex_unlock(&L->lock);20 return 0; // success21 }
If the initial values for the semaphore is S = 0, A = 0, B =…
If the initial values for the semaphore is S = 0, A = 0, B = 1, how many times “1” will be printed?
Failure to surround a critical section of code that accesses…
Failure to surround a critical section of code that accesses/changes a shared variable may result in what type of error?
Suppose there are N workers concurrently running the followi…
Suppose there are N workers concurrently running the following worker function with arbitrary op_code parameters. As we can see, there are two different semaphores r0 and r1 declared in the following code. They are respectively initialized with value R0 and R1. N, R0, and R1 are all positive integers. do_task_A() and do_task_B() functions won’t get stuck. 1 sem_t r0; // Initialized with value R02 sem_t r1; // Initialized with value R134 void *worker(void *op_code) {5 switch (*(int *)op_code) {6 case 0:7 sem_wait(&r0);8 sem_wait(&r1);910 do_task_A();1112 sem_post(&r1);13 sem_post(&r0);14 case 1:15 sem_wait(&r1);16 sem_wait(&r0);1718 do_task_B();1920 sem_post(&r0);21 sem_post(&r1);22 }23 }
Lock Implementations, Hardware primitives, and Projects
Lock Implementations, Hardware primitives, and Projects
If the initial values for the semaphore is S = 0, A = 0, B =…
If the initial values for the semaphore is S = 0, A = 0, B = 0, how many times “1” will be printed?
Outline the common geological and biogeochemical events that…
Outline the common geological and biogeochemical events that were involved in triggering the Paleoproterozoic and the first Neoproterozoic global glaciations. What was one of the key consequences of both these events in terms of the Earth’s atmosphere? (10 pts)
The very low del13C values registered by ca. 2.5-2.7 Ga kero…
The very low del13C values registered by ca. 2.5-2.7 Ga kerogen in Pilbara black shales is thought to indicate the rise of aerobic life as recorded in the biomass of aerobic methane-oxidizing bacteria.
What component(s) of a useful molecular evolutionary chronom…
What component(s) of a useful molecular evolutionary chronometer (i.e. a gene) provides information required to make phylogenetic inferences, e.g. to construct a phylogenetic tree: