mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
* Move collections.deque() in from the sandbox
* Add unittests, newsitem, and whatsnew * Apply to Queue.py mutex.py threading.py pydoc.py and shlex.py * Docs are forthcoming
This commit is contained in:
parent
141d4e5643
commit
756b3f3c15
15 changed files with 983 additions and 57 deletions
|
@ -12,11 +12,13 @@ Of course, no multi-threading is implied -- hence the funny interface
|
|||
for lock, where a function is called once the lock is aquired.
|
||||
"""
|
||||
|
||||
from collections import deque
|
||||
|
||||
class mutex:
|
||||
def __init__(self):
|
||||
"""Create a new mutex -- initially unlocked."""
|
||||
self.locked = 0
|
||||
self.queue = []
|
||||
self.queue = deque()
|
||||
|
||||
def test(self):
|
||||
"""Test the locked bit of the mutex."""
|
||||
|
@ -44,7 +46,7 @@ class mutex:
|
|||
"""Unlock a mutex. If the queue is not empty, call the next
|
||||
function with its argument."""
|
||||
if self.queue:
|
||||
function, argument = self.queue.pop(0)
|
||||
function, argument = self.queue.popleft()
|
||||
function(argument)
|
||||
else:
|
||||
self.locked = 0
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue