GradePack

    • Home
    • Blog
Skip to content
bg
bg
bg
bg

GradePack

What will thread p1 print as the value of balance?

What will thread p1 print as the value of balance?

Read Details

A context switch between threads of different processes requ…

A context switch between threads of different processes requires the flushing of the TLB or tracking of ASID.

Read Details

Select the option that best describes this completed code. C…

Select the option that best describes this completed code. Create shared mutex lock and cond1 & cond2 condition variable and initialize//COMPLETION BEFORE EVEN PRINTpthread_mutex_lock(&mutex);while (counter %2 != 0)   pthread_cond_wait(&cond1,&mutex);//COMPLETION AFTER EVEN PRINTpthread_cond_signal(&cond2);pthread_mutex_unlock(&mutex);//COMPLETION BEFORE ODD PRINTpthread_mutex_lock(&mutex);while (counter %2 == 0)   pthread_cond_wait(&cond2,&mutex);//COMPLETION AFTER ODD PRINTpthread_cond_signal(&cond1);pthread_mutex_unlock(&mutex);

Read Details

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?

Read Details

Four threads are started to work together to take turns prin…

Four threads are started to work together to take turns printing out each integer once in sequential order from 1 up to some maximum.  Two of the threads are executing printEven() and the other two threads are executing printOdd().  The following code is a partial implementation of the functions the threads are executing and the shared variables between them. int MAX = 1000; int counter = 1; //the next number to be printed //two threads execute this function void* printEven(void* arg) { for (int i = 0; i < MAX; i++) { // COMPLETION BEFORE EVEN PRINT printf("Even: %d\n", counter); counter++; // COMPLETION AFTER EVEN PRINT } return NULL; } //two threads execute this function void* printOdd(void* arg) { for (int i = 0; i < MAX; i++) { // COMPLETION BEFORE ODD PRINT printf("Odd: %d\n", counter); counter++; // COMPLETION AFTER ODD PRINT } return NULL; }

Read Details

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?

Read Details

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 }

Read Details

What is the maximum number of threads that could be executin…

What is the maximum number of threads that could be executing at the same time?

Read Details

A semaphore should be initialized to 0 to use it as a mutex…

A semaphore should be initialized to 0 to use it as a mutex lock.

Read Details

If a thread releases the resources it is holding because it…

If a thread releases the resources it is holding because it cannot acquire the remaining resources it needs then deadlock cannot occur.

Read Details

Posts pagination

Newer posts 1 … 43,479 43,480 43,481 43,482 43,483 … 79,790 Older posts

GradePack

  • Privacy Policy
  • Terms of Service
Top