diff options
author | R David Murray <rdmurray@bitdance.com> | 2014-10-04 21:45:15 (GMT) |
---|---|---|
committer | R David Murray <rdmurray@bitdance.com> | 2014-10-04 21:45:15 (GMT) |
commit | f5387c0d6d57f0c118ddfb0b9653b5f208de2940 (patch) | |
tree | f396c16a4f5244fd6b3a236d9d25ee97c4dea265 /Lib/threading.py | |
parent | 5f6a7556bf3071cc1b1ad409cc3ae41379994df1 (diff) | |
parent | b186f1df41da42d774ac9278588acc2bd11a59a8 (diff) | |
download | cpython-f5387c0d6d57f0c118ddfb0b9653b5f208de2940.zip cpython-f5387c0d6d57f0c118ddfb0b9653b5f208de2940.tar.gz cpython-f5387c0d6d57f0c118ddfb0b9653b5f208de2940.tar.bz2 |
Merge: #11866: Eliminate race condition in the computation of names for new threads.
Diffstat (limited to 'Lib/threading.py')
-rw-r--r-- | Lib/threading.py | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/Lib/threading.py b/Lib/threading.py index f7422dd..24cc911 100644 --- a/Lib/threading.py +++ b/Lib/threading.py @@ -6,7 +6,7 @@ import _thread from time import monotonic as _time from traceback import format_exc as _format_exc from _weakrefset import WeakSet -from itertools import islice as _islice +from itertools import islice as _islice, count as _count try: from _collections import deque as _deque except ImportError: @@ -729,11 +729,10 @@ class BrokenBarrierError(RuntimeError): # Helper to generate new thread names -_counter = 0 +_counter = _count().__next__ +_counter() # Consume 0 so first non-main thread has id 1. def _newname(template="Thread-%d"): - global _counter - _counter += 1 - return template % _counter + return template % _counter() # Active thread administration _active_limbo_lock = _allocate_lock() |