diff options
author | Kumar Aditya <kumaraditya@python.org> | 2025-01-01 12:30:47 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-01-01 12:30:47 (GMT) |
commit | bb9d955e16c5578bdbc72750fbbffc8313559109 (patch) | |
tree | d37a4aca10256f4627388f58b3683c1bee7b4a1d /Lib | |
parent | d903b17499b1a3bfb3ea848f6a1b6da02eac3328 (diff) | |
download | cpython-bb9d955e16c5578bdbc72750fbbffc8313559109.zip cpython-bb9d955e16c5578bdbc72750fbbffc8313559109.tar.gz cpython-bb9d955e16c5578bdbc72750fbbffc8313559109.tar.bz2 |
gh-128277: remove unnecessary critical section from `socket.close` (#128305)
Remove unnecessary critical section from `socket.close` as it now uses relaxed atomics for `sock_fd`.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_socket.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py index aac213e..faf326d 100644 --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -7075,6 +7075,26 @@ class SendRecvFdsTests(unittest.TestCase): self.assertEqual(data, str(index).encode()) +class FreeThreadingTests(unittest.TestCase): + + def test_close_detach_race(self): + s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + + def close(): + for _ in range(1000): + s.close() + + def detach(): + for _ in range(1000): + s.detach() + + t1 = threading.Thread(target=close) + t2 = threading.Thread(target=detach) + + with threading_helper.start_threads([t1, t2]): + pass + + def setUpModule(): thread_info = threading_helper.threading_setup() unittest.addModuleCleanup(threading_helper.threading_cleanup, *thread_info) |