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
5cee47f3
Kaydet (Commit)
5cee47f3
authored
Ock 11, 2011
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Add entry for Barrier objects.
üst
a3e8f3d8
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
46 additions
and
5 deletions
+46
-5
threading.rst
Doc/library/threading.rst
+1
-1
3.2.rst
Doc/whatsnew/3.2.rst
+43
-1
threading.py
Lib/threading.py
+2
-3
No files found.
Doc/library/threading.rst
Dosyayı görüntüle @
5cee47f3
...
...
@@ -868,7 +868,7 @@ As an example, here is a simple way to synchronize a client and server thread::
constructor.
The return value is an integer in the range 0 to *parties* -- 1, different
for each thrad. This can be used to select a thread to do some special
for each thr
e
ad. This can be used to select a thread to do some special
housekeeping, e.g.::
i = barrier.wait()
...
...
Doc/whatsnew/3.2.rst
Dosyayı görüntüle @
5cee47f3
...
...
@@ -817,7 +817,49 @@ collections
(Contributed by Raymond Hettinger.)
.. XXX threading.py and Barrier objects
threading
---------
The :mod:`threading` module has a new :class:`~threading.Barrier`
synchronization class for making multiple threads wait until all of them have
reached a common barrier point. Barriers are useful for making sure that a task
with multiple preconditions does not run until all of the predecessor tasks are
complete.
Barriers can work with an arbitrary number of threads. This is a generalization
of a `Rendezvous <http://en.wikipedia.org/wiki/Synchronous_rendezvous>`_ which
is defined for only two threads.
The barrier is designed to be cyclic, making it reusable once all of the
waiting threads are released.
If any of the predecessor tasks can hang or be delayed, a barrier can be created
with an optional *timeout* parameter. Then if the timeout period elapses before
all the predecessor tasks reach the barrier point, all waiting threads are
released and a :exc:`~threading.BrokenBarrierError` exception is raised.
Example of using barriers::
def get_votes(site):
ballots = conduct_election(site)
all_polls_closed.wait() # do not count until all polls are closed
summarize(ballots)
all_polls_closed = Barrier(len(sites))
for site in sites(get_votes(site)):
Thread(target=get_votes, args=(site,)).start()
In this example, the barrier enforces a rule that votes cannot be counted at any
polling site until all polls are closed. Notice how a solution with a barrier
is similar to one with :meth:`threading.Thread.join`, but the threads stay alive
and continue to do work (summarizing ballots) after the barrier point is
crossed.
See `Barrier Synchronization Patterns
<http://parlab.eecs.berkeley.edu/wiki/_media/patterns/paraplop_g1_3.pdf>`_
for more examples of how barriers can be used in parallel computing.
(Contributed by Kristján Valur Jónsson in :issue:`8777`.)
datetime
--------
...
...
Lib/threading.py
Dosyayı görüntüle @
5cee47f3
...
...
@@ -17,12 +17,11 @@ from collections import deque
# with the multiprocessing module, which doesn't provide the old
# Java inspired names.
# Rename some stuff so "from threading import *" is safe
__all__
=
[
'active_count'
,
'Condition'
,
'current_thread'
,
'enumerate'
,
'Event'
,
'Lock'
,
'RLock'
,
'Semaphore'
,
'BoundedSemaphore'
,
'Thread'
,
'Lock'
,
'RLock'
,
'Semaphore'
,
'BoundedSemaphore'
,
'Thread'
,
'Barrier'
,
'Timer'
,
'setprofile'
,
'settrace'
,
'local'
,
'stack_size'
]
# Rename some stuff so "from threading import *" is safe
_start_new_thread
=
_thread
.
start_new_thread
_allocate_lock
=
_thread
.
allocate_lock
_get_ident
=
_thread
.
get_ident
...
...
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