Semaphores and concurrent programming

后端 未结 3 1839
悲哀的现实
悲哀的现实 2021-01-02 19:08

For a homework assignment i need to program the following scenario. This is going to be done using semaphores using BACI (which is C--)

There are 2 unisex restrooms

3条回答
  •  情深已故
    2021-01-02 20:05

    Here is what I have. This allows 1 person in the restroom at a time without deadlock or starvation. I'm in need of assistance with how to make it so 4 people can be in the restroom at a time.

    const int Delayx = 60;
    int i;
    semaphore max_capacity;
    semaphore woman;
    semaphore man;
    semaphore mutex;
    
    void Delay(void)
    {
        int DelayTime;
        DelayTime = random(Delayx);
        for (i = 0; i

提交回复
热议问题