Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Consider the pseudocode shown below. After initializing the semaphores, s1 and s

ID: 3548751 • Letter: C

Question

Consider the pseudocode shown below. After initializing the semaphores, s1 and s2, three threads are created executing runA(), runB(), and runC(), respectively.


How would can the sychronization code be modified, adding at most one more semaphore and/or changing the semaphores' initial count values if necessary and adding or removing semaphore operations, so that the only possible output is "WILDCATS".

Consider the pseudocode shown below. After initializing the semaphores, s1 and s2, three threads are created executing runA(), runB(), and runC(), respectively.

Explanation / Answer

semaphore s1 = 0;

semaphore s2 = 0;

semaphore s3 = 0;


void *runA()

{

output 'W';

sem_post(&s1);//runB

sem_wait(&s3);//wait for runC

output 'D'

sem_post(&s1);//runB

sem_wait(&s3);//wait for runC

output 'T';

sem_post(&s1);//runB

return;

}


void *runB()

{

sem_wait(&s1);//wait for runA

output 'I';

sem_post(&s2);//runC

sem_wait(&s1);//wait for runA

output 'C';

sem_post(&s2);//runC

sem_wait(&s1);//wait for runA

output 'S';

return;

}


void *runC()

{

sem_wait(&s2);//wait for runB

output 'L';

sem_post(&s3);//runA

sem_wait(&s2);//wait for runB

output 'A';

sem_post(&s3);//runA

}


I realize that this is super confusing but if you see clearly there is a pattern that is repeated.

In runA we'll output W, send signal to start runB and wait for runC to complete hoping that runC gets started from somewhere else.

for running runB we'll do "sem_post(&s1)" everytime.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote