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

Write a program for synchronization of the cigarette smokers problem - descripti

ID: 3563758 • Letter: W

Question

 Write a program for synchronization of the cigarette smokers problem - description as given in the link : http://en.wikipedia.org/wiki/Cigarette_smokers_problem.  
 Model each agent as a thread. Do not use any synchronization related system calls/library functions. Instead, synchronization should be done using your own implementation ( similar to Bakery Algorithm ).  
 General guidelines: . Design your code so that it is easy to demonstrate the race condition by   omitting the entry_section and exit_section (i.e. if you leave out the   entry_section and exit_section, your programme should exhibit the   inconsistencies that arise from race conditions). . The behaviour of each agent should have an element of randomness (use a   function like rand() along with sleep() in a suitable way for this). . Include suitable printf functions in each agent so that the sequence of   operations performed by all the agents is clearly understandable. 

Explanation / Answer

Pseudo Code

shared int number[4] = {0,0,0,0}

void Agent(){

   while (TRUE){

       while(number[0] == 0);      

      

       \ pick a random number between i = 1,2,3

       \ number[i] = 1;

       number[0] = 0;      

   }

      

}

void smoker_i(){

   while(TRUE){

       while(number[i] == 0);

  

       \ smoker_i started smoking

       umber[0] == 1;

   }

}

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