Question: I need help with this code. I am trying to do strict alternation but instead of doing it that it just print 10 for thread
I need help with this code. I am trying to do strict alternation but instead of doing it that it just print 10 for thread 1 and 10 for thread 0. Here is my code
#include #include #include int count; int turn = 0;
void* myFunction(void* arg) { int actual_arg = *((int*) arg); for(unsigned int i = 0; i
// HINT: It is not necessary to make any changes in main() int main() { int rc[2]; pthread_t ids[2]; int args[2]; count = 0; for(unsigned int i = 0; i
and here is my output



Please dont do it for me just tell me where my code is wrong. Thank you!
Thread #1 count = 1Thread #0 count = Thread #1 count = 3 Thread #1 count = 4 Thread #1 count = 5 Thread #1 count = 6 Thread #1 count = 7 Thread #1 count = 8 = Thread #0 count 12 Thread #0 count = 13 Thread #0 count = 14 Thread #0 count = 15 Thread #0 count = 16 Thread #0 count = 17 Thread #0 count = 19 Thread #0 count = 20 Final count = 20 Thread #1 count = 1Thread #0 count = Thread #1 count = 3 Thread #1 count = 4 Thread #1 count = 5 Thread #1 count = 6 Thread #1 count = 7 Thread #1 count = 8 = Thread #0 count 12 Thread #0 count = 13 Thread #0 count = 14 Thread #0 count = 15 Thread #0 count = 16 Thread #0 count = 17 Thread #0 count = 19 Thread #0 count = 20 Final count = 20
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
