Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.25 KB | None | 0 0
  1. void lock(int* semaphore)
  2. {
  3.     while (not compare_and_exchange(*semaphore, 0, 1))
  4.     {
  5.         futex(FUTEX_WAIT, semaphore, 1);
  6.     }
  7. }
  8.  
  9. void unlock(int* semaphore)
  10. {
  11.     if (compare_and_exchange(*semaphore, 1, 0))
  12.     {
  13.         futex(FUTEX_WAKE, semaphore, 1);
  14.     }
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement