Single answer: What would be the output at LINE C and LINE P…

Single answer: What would be the output at LINE C and LINE P when the program below executes? #include #include int value = 0;void *runner(void *param) {  value = 5;  printf(“%d”,value); /* LINE C */  pthread_exit(0);}int main(int argc, char *argv[]) {  pid_t pid;  pthread_t tid;  pthread_attr_t attr;  pthread_attr_init(&attr);  pthread create(&tid,&attr,runner,NULL);  pthread_join(tid,NULL);  printf(“%d”,value); /* LINE P */}

Multiple answers: Suppose the followings while executing a p…

Multiple answers: Suppose the followings while executing a program execution on a 32bit x86 CPU computer system; %esp=0xffffcf8c %eip=0x804842b. The instruction at the memory address 0x804842b is call 0x80483dd. 0x8048430 is the next sequential instruction memory address after 0x804842b Select three statements that are *CORRECT* right after CPU fetch-and-executes the instruction “call 0x80483dd” at 0x804842b. 

Single answer: A semaphore variable can be used to order the…

Single answer: A semaphore variable can be used to order the execution of two treads T1 and T2. Select one *CORRECT* answer that correctly uses the semaphore variable “synch” to produce the output “BA” regardless of the order of scheduling on T1 and T2.    

Multiple answers: Select two answers that are *CORRECT* when…

Multiple answers: Select two answers that are *CORRECT* when the following program executes. You can reference pthread man page if you need. #include #include #include #define CORE 4#define MAX 8pthread_t thread[CORE];int mat_A[MAX][MAX], mat_B[MAX][MAX], sum[MAX][MAX];void* add(void* arg) {  int i, j;  int core = (int)arg; for (i = core * MAX / 4; i < (core + 1) * MAX / 4; i++)   for (j = 0; j < MAX; j++)      sum[i][j] = mat_A[i][j] + mat_B[i][j];  return NULL;}int main() {  int i, j, step = 0;                                                                  for (i = 0; i < MAX; i++)     for (j = 0; j < MAX; j++) {      mat_A[i][j] = rand() % 10;      mat_B[i][j] = rand() % 10;    }  for (i = 0; i < CORE; i++) {    pthread_create(&thread[i], NULL, &add                   (void*)step);    step++;  }  for (i = 0; i < CORE; i++)    pthread_join(thread[i], NULL);  return 0;}

Single answer: xchgl is a x86 machine instruction that reads…

Single answer: xchgl is a x86 machine instruction that reads a 32bit value from a memory location and sets a new value to the same memory location as a single atomic instruction. The following xchg is the mutual exclusion (mutex) implemented in xv6 os kernel using a xchgl x86 instruction. For your understanding, the machine effects are described in C.   static inline int xchg(volatile int *addr, int newval) { uint result; /* atomic read followed by update in a C version */ result = *addr; *addr = new; return result;} Select one that *CORRECTLY* implements a mutual lock to enter a critical section (mutual exclusion) using the xchg above.

Copy the program below and revise it to make the program pro…

Copy the program below and revise it to make the program produce the same output every time when it executes #include #include #include int value;typedef struct __myarg_t {  int x;  int y;} myarg_t;pthread_t t1,t2;pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;void *work(void *arg) {  myarg_t *m = (myarg_t *) arg; int local1 = m->x; int count = m->y; for (int i = 0; i < count ; i++) {   value = value + local1;  }  return NULL;}int main(){  value = 0; myarg_t arg1 = {2, 1000}; myarg_t arg2 = {3, 1000};  int rc;  value = 0; rc = pthread_create(&t1, NULL, &work, (void*)&arg1);  if (rc < 0) {   perror("pthread creation error for thread t1\n");    return -1;  } rc = pthread_create(&t2, NULL, &work, (void*)&arg2);  if (rc < 0) {   perror("pthread creation error for thread t2\n");    return -1;  }  pthread_join(t1, NULL);  pthread_join(t2, NULL); printf("%d\n", value);  return 0;}