Created
February 25, 2015 20:04
-
-
Save itolosa/c67aa7ac61ba967a35ff to your computer and use it in GitHub Desktop.
Mutex implementation with no spinlocks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def wait(): | |
| condmut.acquire() | |
| sleepQueue.enqueue(P) | |
| condmut.release() | |
| sleep(P) | |
| def signal(): | |
| condmut.acquire() | |
| P = sleepQueue.dequeue(NoWait) | |
| if not P: | |
| return -1 | |
| signal(P) | |
| condmut.release() | |
| def wait(): | |
| mutex.acquire() | |
| if deactivate: | |
| mutex.release() | |
| perform() | |
| else: | |
| in_count += 1 | |
| mutex.release() | |
| x.wait() | |
| auxmut.acquire() | |
| out_count += 1 | |
| auxmut.release() | |
| if deactivate: | |
| perform() | |
| def abort(): | |
| mutex.acquire() | |
| deactivate = true | |
| while out_count < in_count: | |
| x.signal() | |
| mutex.release() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment