[issue8777] Add threading.Barrier

Jeffrey Yasskin report at bugs.python.org
Mon May 24 19:31:32 CEST 2010


Jeffrey Yasskin <jyasskin at gmail.com> added the comment:

You should probably mention that pthread_barrier and java.util.concurrent.CyclicBarrier are prior art for this. I'm thinking about them when looking at the API to see whether your differences make sense.

"enter" seems to be the wrong term for this, since there's no matching "exit" call. "wait" or "block" seem better.

Both pthread_barrier and CyclicBarrier provide a way to identify a unique thread from each group. pthread_barrier_wait returns true in exactly one thread, while CyclicBarrier runs a callback while all other threads are still paused. I'd be inclined to use CyclicBarrier's interface here, although then you have to define what happens when the action raises an exception.

_release should notify_all after its loop.

adjust_count makes me nervous. Is there a context manager interface that would make this cleaner/safer?

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue8777>
_______________________________________


More information about the Python-bugs-list mailing list