Advertisement
Guest User

Untitled

a guest
Dec 7th, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. void wait(int semaphoreIndex) {
  2. struct semaphore *Sem = &Forks[semaphoreIndex];
  3.  
  4. Sem->count-- ;
  5. if (Sem->count < 0) {
  6.  
  7. // Find the sem queue tail
  8. struct PCB *SQT = Sem->Sem_Queue;
  9. while (SQT->Next_PCB != NULL) {
  10. SQT = SQT->Next_PCB;
  11. }
  12. // Add process to the end of the sem queue
  13. SQT->Next_PCB = Current;
  14. SQT->Next_PCB->Next_PCB = NULL;
  15.  
  16. printf("Process PID: %d was BLOCKED\n", Current->PID);
  17. }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement