Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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;

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Principles Of Database Systems With Internet And Java Applications

Authors: Greg Riccardi

1st Edition

020161247X, 978-0201612479

More Books

Students also viewed these Databases questions