Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void lock(int* semaphore)
- {
- while (not compare_and_exchange(*semaphore, 0, 1))
- {
- futex(FUTEX_WAIT, semaphore, 1);
- }
- }
- void unlock(int* semaphore)
- {
- if (compare_and_exchange(*semaphore, 1, 0))
- {
- futex(FUTEX_WAKE, semaphore, 1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement