GradePack

    • Home
    • Blog
Skip to content
bg
bg
bg
bg

GradePack

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

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?

Read Details

Reactions between CO2 and H2 in mid-ocean ridge hydrothermal…

Reactions between CO2 and H2 in mid-ocean ridge hydrothermal systems produce (choose all that apply):

Read Details

The deposition of Banded Iron Formation (BIF) as early as 3….

The deposition of Banded Iron Formation (BIF) as early as 3.0 Ga can only be explained by the existence of early oxygenic photosynthesis.

Read Details

Match the geological location/source on the left with the ev…

Match the geological location/source on the left with the evidence for life on the right. Note: one of the choices on the right should be used TWICE.

Read Details

Posts pagination

Newer posts 1 … 43,615 43,616 43,617 43,618 43,619 … 79,925 Older posts

GradePack

  • Privacy Policy
  • Terms of Service
Top