Skip to content

Commit 87249ab

Browse files
committed
address review comments.
1 parent 28118a0 commit 87249ab

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

Doc/c-api/init.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -988,7 +988,7 @@ attempts to acquire a lock owned by the blocked thread, or otherwise waits on
988988
the blocked thread.
989989
990990
Gross? Yes. This prevents random crashes and/or unexpectedly skipped C++
991-
finalizations further up the call stack when such threads were forcably exited
991+
finalizations further up the call stack when such threads were forcibly exited
992992
here in CPython 3.13 and earlier. The CPython runtime GIL acquiring C APIs
993993
have never had any error reporting or handling expectations at GIL acquisition
994994
time that would've allowed for graceful exit from this situation. Changing that

Include/pythread.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@ typedef enum PyLockStatus {
1717

1818
PyAPI_FUNC(void) PyThread_init_thread(void);
1919
PyAPI_FUNC(unsigned long) PyThread_start_new_thread(void (*)(void *), void *);
20-
/* Terminates the current thread.
20+
/* Terminates the current thread. Considered unsafe.
2121
*
2222
* WARNING: This function is only safe to call if all functions in the full call
2323
* stack are written to safely allow it. Additionally, the behavior is
2424
* platform-dependent. This function should be avoided, and is no longer called
2525
* by Python itself. It is retained only for compatibility with existing C
2626
* extension code.
2727
*
28-
* With pthreads, calls `pthread_exit` which attempts to unwind the stack and
29-
* call C++ destructors. If a `noexcept` function is reached, the program is
30-
* terminated.
28+
* With pthreads, calls `pthread_exit` causes some libcs (glibc?) to attempt to
29+
* unwind the stack and call C++ destructors; if a `noexcept` function is
30+
* reached, they may terminate the process. Others (macOS) do unwinding.
3131
*
3232
* On Windows, calls `_endthreadex` which kills the thread without calling C++
3333
* destructors.

Modules/_testcapimodule.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3333,7 +3333,7 @@ test_critical_sections(PyObject *module, PyObject *Py_UNUSED(args))
33333333
#ifdef _POSIX_THREADS
33343334
static void finalize_thread_hang_cleanup_callback(void *Py_UNUSED(arg)) {
33353335
// Should not reach here.
3336-
assert(0 && "pthread thread termination was triggered unexpectedly");
3336+
Py_FatalError("pthread thread termination was triggered unexpectedly");
33373337
}
33383338
#endif
33393339

@@ -3342,12 +3342,12 @@ static void finalize_thread_hang_cleanup_callback(void *Py_UNUSED(arg)) {
33423342
// Must be called with a single nullary callable function that should block
33433343
// (with GIL released) until finalization is in progress.
33443344
static PyObject *
3345-
finalize_thread_hang(PyObject *self, PyObject *arg)
3345+
finalize_thread_hang(PyObject *self, PyObject *callback)
33463346
{
33473347
#ifdef _POSIX_THREADS
33483348
pthread_cleanup_push(finalize_thread_hang_cleanup_callback, NULL);
33493349
#endif
3350-
PyObject_CallNoArgs(arg);
3350+
PyObject_CallNoArgs(callback);
33513351
// Should not reach here.
33523352
Py_FatalError("thread unexpectedly did not hang");
33533353
#ifdef _POSIX_THREADS

0 commit comments

Comments
 (0)