Note that there are some explanatory texts on larger screens.

plurals
  1. POSemaphores and concurrent programming
    text
    copied!<p>For a homework assignment i need to program the following scenario. This is going to be done using semaphores using BACI (which is C--) </p> <p>There are 2 unisex restrooms that can hold 4 people each. Since it is unisex only people of the same sex can be in the restroom at the same time and FIFO is not important. I have the basic "algorithm" in my head to handle 4 men and 4 woman for 1 restroom. But i don't know how to code this. Any help would be greatly appreciated. Here is what I have.</p> <pre><code>Woman: Check to see if there are any men in the restroom. If so "wait". If no men check to see if there are 4 people. If so "wait". If no men and not 4 use restroom. When leaving signal there is a vacancy. If last woman signal the men if they are waiting if not signal the woman. Man: check to see if there are any woman in the restroom. if so "wait" If no woman check to see if there are 4 people. If so "wait". If no woman and not 4 use restroom. when leaving signal there is a vacancy. if last man signal the women if they are waiting if not signal the men. </code></pre> <p>These additional instructions were provided </p> <ul> <li><p>Use random FOR loops to simulate the passage of time in the appropriate places. This can be easily done by using a Delay function:</p> <pre><code>void Delay (void) { int i; int DelayTime; DelayTime = random (DELAY); for (i = 0; i &lt; DelayTime; i++): } </code></pre></li> <li><p>where const int DELAY = some number from 10 to 100. </p></li> <li>Print and format output nicely and print messages in such a way that by reading the output, one can trace the execution order.</li> <li>Set the processes up to loop forever, and use control C (or control break) to stop your program.</li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload