Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

pl do not copy answer in chegg. I want answer either true or false The first known correct software solution to the critical-section problem for

pl do not copy answer in chegg.

I want answer either true or false

The first known correct software solution to the critical-section problem for n threads with a lower bound on waiting of n 1 turns was presented by Eisenberg and McGuire. Given in the following code implementation of this solution, compile and run for 5 threads. If the code runs, can it be applied to any number of threads (of course as long as the system can support)?

#include  #include  #include  #define N 5 //Nthreads pthread_t thread_id[N]; enum pstate {idle, want_in, in_cs}; enum pstate flag[N]; int turn; int j;
void leaveCS(int i){ j = (turn+1) % N; while (flag[j]==idle) j = (j+1)%N; turn = j; flag[i]=idle; printf("Thread %d left Critical Section ", i); } void enterCS(int i){ while (1) { flag[i] = want_in; j = turn; while (j != i) { if (flag[j] != idle) j = turn; else j = (j+1) % N; } flag[i] = in_cs; j = 0; while ( (j=N) && (turn==i || flag[turn]==idle)) break; } printf("Thread %d entered Critical Section ", i); } void *thread(void* arg) { int i = (int)arg; enterCS(i); sleep(5); leaveCS(i); printf("Goodbye "); return 0; } int main(){ int i; for (i = 0; i < N; i++) pthread_create(&thread_id[i], NULL, thread, (void*)(size_t)i); for (i = 0; i < N; i++) pthread_join(thread_id[i], NULL); return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions