mirror of
https://github.com/python/cpython.git
synced 2025-08-03 08:34:29 +00:00
Whole lotta changes.
This commit is contained in:
parent
d69a84b01e
commit
228b8e88bc
52 changed files with 2276 additions and 434 deletions
|
@ -2,6 +2,7 @@
|
|||
|
||||
# Create a bunch of threads, let each do some work, wait until all are done
|
||||
|
||||
from test_support import verbose
|
||||
import whrandom
|
||||
import thread
|
||||
import time
|
||||
|
@ -19,9 +20,11 @@ def task(ident):
|
|||
whmutex.acquire()
|
||||
delay = whrandom.random() * numtasks
|
||||
whmutex.release()
|
||||
print 'task', ident, 'will run for', delay, 'sec'
|
||||
if verbose:
|
||||
print 'task', ident, 'will run for', delay, 'sec'
|
||||
time.sleep(delay)
|
||||
print 'task', ident, 'done'
|
||||
if verbose:
|
||||
print 'task', ident, 'done'
|
||||
mutex.acquire()
|
||||
running = running - 1
|
||||
if running == 0:
|
||||
|
@ -33,7 +36,8 @@ def newtask():
|
|||
global next_ident, running
|
||||
mutex.acquire()
|
||||
next_ident = next_ident + 1
|
||||
print 'creating task', next_ident
|
||||
if verbose:
|
||||
print 'creating task', next_ident
|
||||
thread.start_new_thread(task, (next_ident,))
|
||||
running = running + 1
|
||||
mutex.release()
|
||||
|
@ -84,11 +88,14 @@ def task2(ident):
|
|||
whmutex.acquire()
|
||||
delay = whrandom.random() * numtasks
|
||||
whmutex.release()
|
||||
print 'task', ident, 'will run for', delay, 'sec'
|
||||
if verbose:
|
||||
print 'task', ident, 'will run for', delay, 'sec'
|
||||
time.sleep(delay)
|
||||
print 'task', ident, 'entering barrier', i
|
||||
if verbose:
|
||||
print 'task', ident, 'entering barrier', i
|
||||
bar.enter()
|
||||
print 'task', ident, 'leaving barrier', i
|
||||
if verbose:
|
||||
print 'task', ident, 'leaving barrier', i
|
||||
mutex.acquire()
|
||||
running = running - 1
|
||||
if running == 0:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue