gh-112075: Remove critical section in dict.get by eendebakpt · Pull Request #129336 · python/cpython
Expand Up
@@ -5,7 +5,7 @@
from ast import Or from functools import partial from threading import Thread from threading import Barrier, Thread from unittest import TestCase
try: Expand Down Expand Up @@ -142,6 +142,27 @@ def writer_func(l): for ref in thread_list: self.assertIsNone(ref())
def test_racing_get_set_dict(self): """Races getting and setting a dict should be thread safe""" THREAD_COUNT = 10 barrier = Barrier(THREAD_COUNT) def work(d): barrier.wait() for _ in range(1000): d[10] = 0 d.get(10, None) _ = d[10]
d = {} worker_threads = [] for ii in range(THREAD_COUNT): worker_threads.append(Thread(target=work, args=[d])) for t in worker_threads: t.start() for t in worker_threads: t.join()
def test_racing_set_object_dict(self): """Races assigning to __dict__ should be thread safe""" class C: pass Expand Down
from ast import Or from functools import partial from threading import Thread from threading import Barrier, Thread from unittest import TestCase
try: Expand Down Expand Up @@ -142,6 +142,27 @@ def writer_func(l): for ref in thread_list: self.assertIsNone(ref())
def test_racing_get_set_dict(self): """Races getting and setting a dict should be thread safe""" THREAD_COUNT = 10 barrier = Barrier(THREAD_COUNT) def work(d): barrier.wait() for _ in range(1000): d[10] = 0 d.get(10, None) _ = d[10]
d = {} worker_threads = [] for ii in range(THREAD_COUNT): worker_threads.append(Thread(target=work, args=[d])) for t in worker_threads: t.start() for t in worker_threads: t.join()
def test_racing_set_object_dict(self): """Races assigning to __dict__ should be thread safe""" class C: pass Expand Down