Question: Please explain why explicitly Consider the following code that uses the POSIX API: pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; void *A(void *arg) { int *p = (int*)

Please explain why explicitly
Consider the following code that uses the POSIX API: pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; void *A(void *arg) { int *p = (int*) arg; pthread_mutex_lock(&lock); *p*= 10; *p += 10; pthread_mutex_unlock (&lock); return NULL; } int foo() { int x = 1; pthread_t threadl; pthread_create(&A_thread, NULL, A, &x); pthread_mutex_lock(&lock); X += 1; pthread_mutex_unlock(&lock); pthread_join(A_thread, NULL); pthread_mutex_lock (&lock); x += 1; pthread_mutex_unlock (&lock); return x; } Assume that none of the pthreads functions called above fail. Which of the following are possible return values of foo() ? Select all that apply. A. O 3 B. O 13 C. O 22 D. O 31 E. O 40 F. foo could hang indefinitely
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
