Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
d3b6842d
Kaydet (Commit)
d3b6842d
authored
May 23, 1994
tarafından
Guido van Rossum
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
added barrier test (by Tim Peters)
üst
f3b4903a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
67 additions
and
2 deletions
+67
-2
test_thread.py
Lib/test/test_thread.py
+67
-2
No files found.
Lib/test/test_thread.py
Dosyayı görüntüle @
d3b6842d
...
...
@@ -7,13 +7,18 @@ import thread
import
time
mutex
=
thread
.
allocate_lock
()
whmutex
=
thread
.
allocate_lock
()
# for calls to whrandom
running
=
0
done
=
thread
.
allocate_lock
()
done
.
acquire
()
numtasks
=
10
def
task
(
ident
):
global
running
delay
=
whrandom
.
random
()
*
10
whmutex
.
acquire
()
delay
=
whrandom
.
random
()
*
numtasks
whmutex
.
release
()
print
'task'
,
ident
,
'will run for'
,
delay
,
'sec'
time
.
sleep
(
delay
)
print
'task'
,
ident
,
'done'
...
...
@@ -33,9 +38,69 @@ def newtask():
running
=
running
+
1
mutex
.
release
()
for
i
in
range
(
10
):
for
i
in
range
(
numtasks
):
newtask
()
print
'waiting for all tasks to complete'
done
.
acquire
()
print
'all tasks done'
class
barrier
:
def
__init__
(
self
,
n
):
self
.
n
=
n
self
.
waiting
=
0
self
.
checkin
=
thread
.
allocate_lock
()
self
.
checkout
=
thread
.
allocate_lock
()
self
.
checkout
.
acquire
()
def
enter
(
self
):
checkin
,
checkout
=
self
.
checkin
,
self
.
checkout
checkin
.
acquire
()
self
.
waiting
=
self
.
waiting
+
1
if
self
.
waiting
==
self
.
n
:
self
.
waiting
=
self
.
n
-
1
checkout
.
release
()
return
checkin
.
release
()
checkout
.
acquire
()
self
.
waiting
=
self
.
waiting
-
1
if
self
.
waiting
==
0
:
checkin
.
release
()
return
checkout
.
release
()
numtrips
=
3
def
task2
(
ident
):
global
running
for
i
in
range
(
numtrips
):
if
ident
==
0
:
# give it a good chance to enter the next
# barrier before the others are all out
# of the current one
delay
=
0.001
else
:
whmutex
.
acquire
()
delay
=
whrandom
.
random
()
*
numtasks
whmutex
.
release
()
print
'task'
,
ident
,
'will run for'
,
delay
,
'sec'
time
.
sleep
(
delay
)
print
'task'
,
ident
,
'entering barrier'
,
i
bar
.
enter
()
print
'task'
,
ident
,
'leaving barrier'
,
i
mutex
.
acquire
()
running
=
running
-
1
if
running
==
0
:
done
.
release
()
mutex
.
release
()
print
'
\n
*** Barrier Test ***'
if
done
.
acquire
(
0
):
raise
ValueError
,
"'done' should have remained acquired"
bar
=
barrier
(
numtasks
)
running
=
numtasks
for
i
in
range
(
numtasks
):
thread
.
start_new_thread
(
task2
,
(
i
,))
done
.
acquire
()
print
'all tasks done'
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment