Kaydet (Commit) fd0107fd authored tarafından Benjamin Peterson's avatar Benjamin Peterson

use True and False

üst 9f4f56d4
...@@ -20,7 +20,7 @@ from collections import deque ...@@ -20,7 +20,7 @@ from collections import deque
class mutex: class mutex:
def __init__(self): def __init__(self):
"""Create a new mutex -- initially unlocked.""" """Create a new mutex -- initially unlocked."""
self.locked = 0 self.locked = False
self.queue = deque() self.queue = deque()
def test(self): def test(self):
...@@ -31,7 +31,7 @@ class mutex: ...@@ -31,7 +31,7 @@ class mutex:
"""Atomic test-and-set -- grab the lock if it is not set, """Atomic test-and-set -- grab the lock if it is not set,
return True if it succeeded.""" return True if it succeeded."""
if not self.locked: if not self.locked:
self.locked = 1 self.locked = True
return True return True
else: else:
return False return False
...@@ -52,4 +52,4 @@ class mutex: ...@@ -52,4 +52,4 @@ class mutex:
function, argument = self.queue.popleft() function, argument = self.queue.popleft()
function(argument) function(argument)
else: else:
self.locked = 0 self.locked = False
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment