mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
gh-115035: Mark ThreadHandles as non-joinable earlier after forking (#115042)
This marks dead ThreadHandles as non-joinable earlier in `PyOS_AfterFork_Child()` before we execute any Python code. The handles are stored in a global linked list in `_PyRuntimeState` because `fork()` affects the entire process.
This commit is contained in:
parent
71239d50b5
commit
b6228b521b
7 changed files with 50 additions and 41 deletions
|
@ -517,6 +517,8 @@ _PyRuntimeState_ReInitThreads(_PyRuntimeState *runtime)
|
|||
return _PyStatus_NO_MEMORY();
|
||||
}
|
||||
|
||||
_PyThread_AfterFork(&runtime->threads);
|
||||
|
||||
return _PyStatus_OK();
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -242,10 +242,6 @@ PyThread_detach_thread(PyThread_handle_t handle) {
|
|||
return (CloseHandle(hThread) == 0);
|
||||
}
|
||||
|
||||
void
|
||||
PyThread_update_thread_after_fork(PyThread_ident_t* ident, PyThread_handle_t* handle) {
|
||||
}
|
||||
|
||||
/*
|
||||
* Return the thread Id instead of a handle. The Id is said to uniquely identify the
|
||||
* thread in the system
|
||||
|
|
|
@ -339,16 +339,6 @@ PyThread_detach_thread(PyThread_handle_t th) {
|
|||
return pthread_detach((pthread_t) th);
|
||||
}
|
||||
|
||||
void
|
||||
PyThread_update_thread_after_fork(PyThread_ident_t* ident, PyThread_handle_t* handle) {
|
||||
// The thread id might have been updated in the forked child
|
||||
pthread_t th = pthread_self();
|
||||
*ident = (PyThread_ident_t) th;
|
||||
*handle = (PyThread_handle_t) th;
|
||||
assert(th == (pthread_t) *ident);
|
||||
assert(th == (pthread_t) *handle);
|
||||
}
|
||||
|
||||
/* XXX This implementation is considered (to quote Tim Peters) "inherently
|
||||
hosed" because:
|
||||
- It does not guarantee the promise that a non-zero integer is returned.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue