summaryrefslogtreecommitdiffstats
path: root/Lib/threading.py
diff options
context:
space:
mode:
authorR David Murray <rdmurray@bitdance.com>2014-10-04 21:43:54 (GMT)
committerR David Murray <rdmurray@bitdance.com>2014-10-04 21:43:54 (GMT)
commitb186f1df41da42d774ac9278588acc2bd11a59a8 (patch)
tree9c6735dea3e1273a09558550e753345e7e2eab10 /Lib/threading.py
parente1618491adc5c0ef214c25d4e3b882e8586a2fee (diff)
downloadcpython-b186f1df41da42d774ac9278588acc2bd11a59a8.zip
cpython-b186f1df41da42d774ac9278588acc2bd11a59a8.tar.gz
cpython-b186f1df41da42d774ac9278588acc2bd11a59a8.tar.bz2
#11866: Eliminate race condition in the computation of names for new threads.
Original patch by Peter Saveliev.
Diffstat (limited to 'Lib/threading.py')
-rw-r--r--Lib/threading.py9
1 files changed, 4 insertions, 5 deletions
diff --git a/Lib/threading.py b/Lib/threading.py
index 7a5a440..37aa3b8 100644
--- a/Lib/threading.py
+++ b/Lib/threading.py
@@ -9,7 +9,7 @@ except ImportError:
from time import time 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:
@@ -726,11 +726,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()