mirror of
https://github.com/python/cpython.git
synced 2025-07-23 19:25:40 +00:00
Issue #12392: fix thread initialization on FreeBSD 6
On FreeBSD6, pthread_kill() doesn't work on the main thread before the creation of the first thread. Create therefore a dummy thread (no-op) a startup to initialize the pthread library. Add also a test for this use case, test written by Charles-François Natali.
This commit is contained in:
parent
fcb17e13da
commit
e71db4450c
2 changed files with 29 additions and 1 deletions
|
@ -295,6 +295,31 @@ class WakeupSignalTests(unittest.TestCase):
|
||||||
|
|
||||||
self.check_signum(signum1, signum2)
|
self.check_signum(signum1, signum2)
|
||||||
|
|
||||||
|
@unittest.skipUnless(hasattr(signal, 'pthread_kill'),
|
||||||
|
'need signal.pthread_kill()')
|
||||||
|
def test_pthread_kill_main_thread(self):
|
||||||
|
# Test that a signal can be sent to the main thread with pthread_kill()
|
||||||
|
# before any other thread has been created (see issue #12392).
|
||||||
|
code = """if True:
|
||||||
|
import threading
|
||||||
|
import signal
|
||||||
|
import sys
|
||||||
|
|
||||||
|
def handler(signum, frame):
|
||||||
|
sys.exit(3)
|
||||||
|
|
||||||
|
signal.signal(signal.SIGUSR1, handler)
|
||||||
|
signal.pthread_kill(threading.get_ident(), signal.SIGUSR1)
|
||||||
|
sys.exit(1)
|
||||||
|
"""
|
||||||
|
|
||||||
|
with spawn_python('-c', code) as process:
|
||||||
|
stdout, stderr = process.communicate()
|
||||||
|
exitcode = process.wait()
|
||||||
|
if exitcode != 3:
|
||||||
|
raise Exception("Child error (exit code %s): %s" %
|
||||||
|
(exitcode, stdout))
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
import fcntl
|
import fcntl
|
||||||
|
|
||||||
|
|
|
@ -144,7 +144,10 @@ typedef struct {
|
||||||
* Initialization.
|
* Initialization.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef _HAVE_BSDI
|
/* On FreeBSD6, pthread_kill() doesn't work on the main thread before
|
||||||
|
the creation of the first thread */
|
||||||
|
#if defined(_HAVE_BSDI) \
|
||||||
|
|| (defined(__FreeBSD__) && __FreeBSD_version < 700000)
|
||||||
static
|
static
|
||||||
void _noop(void)
|
void _noop(void)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue