Question: Code to read: #include #include #include #include #include sem_t s1; int c=0,x=0; void *UpdateC1(void *arg) { int i; for(i=0;i void *UpdateC2(void *arg) { int i,x=0;

 Code to read: #include #include #include #include #include sem_t s1; int

Code to read:

#include #include #include #include #include

sem_t s1; int c=0,x=0;

void *UpdateC1(void *arg) { int i; for(i=0;i

void *UpdateC2(void *arg) { int i,x=0; for(i=0;i

int main(int argc, char *argv[]) { int rt,i; pthread_t t[2];

if(sem_init(&s1, 0, 1)==-1)//Initialize the semaphore; { fprintf(stderr,"sem_init failed. errno=%d ",errno); exit(1); } rt=pthread_create( &t[0], NULL, UpdateC1, NULL); if( rt!=0 ) fprintf(stderr,"Thread %d creation failed: %d ", 0,rt); rt=pthread_create( &t[1], NULL, UpdateC2, NULL); if( rt!=0 ) fprintf(stderr,"Thread %d creation failed: %d ", 1,rt);

for(i=0;i

printf ("\t%c\t%c ",'a'+(c%2),'a'+(x%2)); return 0; }

3. Read given code RaceOrNot3.c and write all possible outputs of the program. Assume there will be no thread creation or joining failures or semaphore failures. If you believe there is only one possible output, you just need to write that output

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!