Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. #define FALSE 0
  2. #define TRUE 1
  3. #define N 2 /* number of processes */
  4.  
  5. int turn; /* whose turn is it? */
  6. int interested[N]; /* all values initially 0 (FALSE)*/
  7. void enter_region(int process) /* process is 0 or 1 */
  8. {
  9. int other; /* number of the other process */
  10. other = 1 - process; /* the opposite of process */
  11. interested[process] = TRUE; /* show that you are interested */
  12. turn = process; /* set flag */
  13. while (turn == process && interested[other] == TRUE) /* null statement */;
  14. }
  15. void leave_region(int process) /* process: who is leaving */
  16. {
  17. interested[process] = FALSE; /* indicate departure from critical region */
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement