Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
fb13cf6
Fix race in `Thread.join()`
mpage Jan 26, 2024
b093e5d
📜🤖 Added by blurb_it.
blurb-it[bot] Feb 1, 2024
1039208
Fix NEWS entry
mpage Feb 1, 2024
196081d
Work around c-analyzer limitation
mpage Feb 5, 2024
19d7af1
Merge branch 'main' into gh-114271-remove-tstate_lock
mpage Feb 5, 2024
c86d349
Merge branch 'main' into gh-114271-remove-tstate_lock
mpage Feb 7, 2024
40e4b36
Merge branch 'main' into gh-114271-remove-tstate_lock
mpage Feb 14, 2024
4ed1083
Merge branch 'main' into gh-114271-remove-tstate_lock
mpage Feb 14, 2024
34b6065
Merge branch 'main' into gh-114271-remove-tstate_lock
mpage Mar 1, 2024
1c82786
Fix two compilation errors post merge
mpage Mar 1, 2024
0e86cf9
Use ThreadHandle as the single abstraction for thread joining
mpage Mar 2, 2024
76bde03
Isolate all logic in _threadmodule
mpage Mar 4, 2024
02123b8
Fix flag
mpage Mar 5, 2024
24c1d47
Note that the once flag serializes both join and set_done
mpage Mar 6, 2024
1a1bfde
Fix unused variable warning
mpage Mar 6, 2024
b3c2c45
Rename ThreadHandleObject to PyThreadHandleObject
mpage Mar 6, 2024
7b9d007
Be consistent with documentation of true values
mpage Mar 6, 2024
5d0dc7a
Threads started using `start_joinable_thread` should be daemon thread…
mpage Mar 6, 2024
11bb826
Remove any remaining handles once the module is cleared
mpage Mar 7, 2024
06f6787
Always have a _ThreadHandle in Thread
mpage Mar 8, 2024
d56f892
Check main thread handle during shutdown
mpage Mar 8, 2024
57e106d
Merge branch 'main' into gh-114271-remove-tstate_lock
mpage Mar 8, 2024
2218c0a
Remove vestigial _PyEventRc declarations
mpage Mar 8, 2024
f9d3290
Remove duplicate declaration
mpage Mar 8, 2024
a7095e4
Revert order change in `_DummyThread.is_alive`
mpage Mar 8, 2024
ccd1c2e
Merge branch 'main' into gh-114271-remove-tstate_lock
mpage Mar 11, 2024
180300c
Add handles to shutdown list before starting the thread
mpage Mar 11, 2024
c486503
Move some code around to remove need for forward decls
mpage Mar 12, 2024
3121623
Simplify start failure path
mpage Mar 12, 2024
ee96259
Merge branch 'main' into gh-114271-remove-tstate_lock
mpage Mar 15, 2024
dc57ed2
Use infinitive in docstring for _shutdown
mpage Mar 15, 2024
48b86ae
Update comment for _make_thread_handle
mpage Mar 15, 2024
9a8ea9b
Merge branch 'main' into gh-114271-remove-tstate_lock
pitrou Mar 16, 2024
339b2e6
Merge branch 'main' into gh-114271-remove-tstate_lock
pitrou Mar 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Isolate all logic in _threadmodule
  • Loading branch information
mpage committed Mar 5, 2024
commit 76bde036984431df51f2c432b4cd078e6a9ccc58
12 changes: 0 additions & 12 deletions Include/cpython/pystate.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,18 +161,6 @@ struct _ts {
*/
uintptr_t critical_section;

/* Boolean storing whether or not this is a daemon thread. */
int is_daemon;

/* Set when the tstate has been cleared and unlinked from the list of
* active tstates.
*
* This is used by _PyInterpreterState_WaitForThreads to wait for all
* non-daemon threads to finish. It cannot be a PyObject because its
* lifetime exceeds the tstate to which it is bound.
*/
struct _PyEventRc *done_event;

int coroutine_origin_tracking_depth;

PyObject *async_gen_firstiter;
Expand Down
1 change: 0 additions & 1 deletion Include/internal/pycore_interp.h
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,6 @@ PyAPI_FUNC(PyInterpreterState *) _PyInterpreterState_LookUpID(int64_t);
PyAPI_FUNC(int) _PyInterpreterState_IDInitref(PyInterpreterState *);
PyAPI_FUNC(int) _PyInterpreterState_IDIncref(PyInterpreterState *);
PyAPI_FUNC(void) _PyInterpreterState_IDDecref(PyInterpreterState *);
PyAPI_FUNC(void) _PyInterpreterState_WaitForThreads(PyInterpreterState *);

extern const PyConfig* _PyInterpreterState_GetConfig(PyInterpreterState *interp);

Expand Down
2 changes: 1 addition & 1 deletion Include/internal/pycore_pythread.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ struct _pythread_runtime_state {
} stubs;
#endif

// Linked list of ThreadHandleObjects
// Linked list of ThreadHandles
struct llist_node handles;
};

Expand Down
19 changes: 6 additions & 13 deletions Lib/threading.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@
_allocate_lock = _thread.allocate_lock
_LockType = _thread.LockType
_thread_shutdown = _thread._shutdown
_get_thread_handle = _thread._get_thread_handle
_make_thread_handle = _thread._make_thread_handle
get_ident = _thread.get_ident
_get_main_thread_ident = _thread._get_main_thread_ident
_is_main_interpreter = _thread._is_main_interpreter
try:
get_native_id = _thread.get_native_id
Expand Down Expand Up @@ -1346,8 +1347,8 @@ class _MainThread(Thread):
def __init__(self):
Thread.__init__(self, name="MainThread", daemon=False)
self._started.set()
self._set_ident()
self._handle = _get_thread_handle()
self._ident = _get_main_thread_ident()
self._handle = _make_thread_handle(self._ident)
if _HAVE_THREAD_NATIVE_ID:
self._set_native_id()
with _active_limbo_lock:
Expand Down Expand Up @@ -1395,7 +1396,7 @@ def __init__(self):
daemon=_daemon_threads_allowed())
self._started.set()
self._set_ident()
self._handle = _get_thread_handle()
self._handle = _make_thread_handle(self._ident)
if _HAVE_THREAD_NATIVE_ID:
self._set_native_id()
with _active_limbo_lock:
Expand Down Expand Up @@ -1529,16 +1530,8 @@ def _shutdown():
for atexit_call in reversed(_threading_atexits):
atexit_call()

# Main thread
if _main_thread.ident == get_ident():
if _is_main_interpreter():
_main_thread._handle._set_done()
else:
# bpo-1596321: _shutdown() must be called in the main thread.
# If the threading module was not imported by the main thread,
# _main_thread is the thread which imported the threading module.
# In this case, ignore _main_thread, similar behavior than for threads
# spawned by C libraries or using _thread.start_new_thread().
pass

# Wait for all non-daemon threads to exit.
_thread_shutdown()
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
Fix a race in ``threading.Thread.join()``.

``threading._MainThread`` now always represents the main thread of the main
interpreter.

``PyThreadState.on_delete`` and ``PyThreadState.on_delete_data`` have been
removed.
Loading