mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
The usual.
This commit is contained in:
parent
887d072cc0
commit
e03c050595
25 changed files with 363 additions and 181 deletions
|
@ -3,12 +3,12 @@
|
|||
# Create a bunch of threads, let each do some work, wait until all are done
|
||||
|
||||
from test_support import verbose
|
||||
import whrandom
|
||||
import random
|
||||
import thread
|
||||
import time
|
||||
|
||||
mutex = thread.allocate_lock()
|
||||
whmutex = thread.allocate_lock() # for calls to whrandom
|
||||
rmutex = thread.allocate_lock() # for calls to random
|
||||
running = 0
|
||||
done = thread.allocate_lock()
|
||||
done.acquire()
|
||||
|
@ -17,9 +17,9 @@ numtasks = 10
|
|||
|
||||
def task(ident):
|
||||
global running
|
||||
whmutex.acquire()
|
||||
delay = whrandom.random() * numtasks
|
||||
whmutex.release()
|
||||
rmutex.acquire()
|
||||
delay = random.random() * numtasks
|
||||
rmutex.release()
|
||||
if verbose:
|
||||
print 'task', ident, 'will run for', round(delay, 1), 'sec'
|
||||
time.sleep(delay)
|
||||
|
@ -85,9 +85,9 @@ def task2(ident):
|
|||
# of the current one
|
||||
delay = 0.001
|
||||
else:
|
||||
whmutex.acquire()
|
||||
delay = whrandom.random() * numtasks
|
||||
whmutex.release()
|
||||
rmutex.acquire()
|
||||
delay = random.random() * numtasks
|
||||
rmutex.release()
|
||||
if verbose:
|
||||
print 'task', ident, 'will run for', round(delay, 1), 'sec'
|
||||
time.sleep(delay)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue