diff options
author | Peter Bierma <zintensitydev@gmail.com> | 2024-12-20 13:02:46 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-20 13:02:46 (GMT) |
commit | ba45e5cdd41a39ce0b3de08bdcfa9d8e28e0e4f3 (patch) | |
tree | f23da518a34216c147f5a25c57644758887f64de /Lib | |
parent | cbfe3023e46b544b80ea1a38a8c900c6fb881554 (diff) | |
download | cpython-ba45e5cdd41a39ce0b3de08bdcfa9d8e28e0e4f3.zip cpython-ba45e5cdd41a39ce0b3de08bdcfa9d8e28e0e4f3.tar.gz cpython-ba45e5cdd41a39ce0b3de08bdcfa9d8e28e0e4f3.tar.bz2 |
gh-127946: Use a critical section for `CFuncPtr` attributes (GH-128109)
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_ctypes/test_cfuncs.py | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/Lib/test/test_ctypes/test_cfuncs.py b/Lib/test/test_ctypes/test_cfuncs.py index 48330c4..e0c1246 100644 --- a/Lib/test/test_ctypes/test_cfuncs.py +++ b/Lib/test/test_ctypes/test_cfuncs.py @@ -5,7 +5,8 @@ from ctypes import (CDLL, c_short, c_ushort, c_int, c_uint, c_long, c_ulong, c_longlong, c_ulonglong, c_float, c_double, c_longdouble) -from test.support import import_helper +from test import support +from test.support import import_helper, threading_helper _ctypes_test = import_helper.import_module("_ctypes_test") @@ -191,6 +192,23 @@ class CFunctions(unittest.TestCase): self.assertEqual(self._dll.tv_i(-42), None) self.assertEqual(self.S(), -42) + @threading_helper.requires_working_threading() + @support.requires_resource("cpu") + @unittest.skipUnless(support.Py_GIL_DISABLED, "only meaningful on free-threading") + def test_thread_safety(self): + from threading import Thread + + def concurrent(): + for _ in range(100): + self._dll.tf_b.restype = c_byte + self._dll.tf_b.argtypes = (c_byte,) + + with threading_helper.catch_threading_exception() as exc: + with threading_helper.start_threads((Thread(target=concurrent) for _ in range(10))): + pass + + self.assertIsNone(exc.exc_value) + # The following repeats the above tests with stdcall functions (where # they are available) |