summaryrefslogtreecommitdiff
path: root/Lib/threading.py
diff options
context:
space:
mode:
authorR David Murray <rdmurray@bitdance.com>2014-10-04 17:40:43 -0400
committerR David Murray <rdmurray@bitdance.com>2014-10-04 17:40:43 -0400
commitd999c3495581ac58a8bd4d7f60e9e14a83937673 (patch)
tree22b6330135b161e94c17939191ec6436b9dad98c /Lib/threading.py
parent429866d13684ed98520c6f7156c18b839f4bcb2f (diff)
downloadcpython-git-d999c3495581ac58a8bd4d7f60e9e14a83937673.tar.gz
#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.py8
1 files changed, 4 insertions, 4 deletions
diff --git a/Lib/threading.py b/Lib/threading.py
index 0438e1f520..27a5511ddc 100644
--- a/Lib/threading.py
+++ b/Lib/threading.py
@@ -11,6 +11,7 @@ except ImportError:
import warnings
from collections import deque as _deque
+from itertools import count as _count
from time import time as _time, sleep as _sleep
from traceback import format_exc as _format_exc
@@ -623,11 +624,10 @@ class _Event(_Verbose):
self.__cond.release()
# 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 = _counter + 1
- return template % _counter
+ return template % _counter()
# Active thread administration
_active_limbo_lock = _allocate_lock()