Skip to content
Prev Previous commit
Next Next commit
add test
  • Loading branch information
Fidget-Spinner committed Jun 7, 2024
commit bda9545ac413922c49b91fad870e12990258ffac
7 changes: 5 additions & 2 deletions Include/internal/pycore_interp.h
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,11 @@ PyAPI_FUNC(PyStatus) _PyInterpreterState_New(

#define RARE_EVENT_INTERP_INC(interp, name) \
do { \
/* saturating add */ \
if (interp->rare_events.name < UINT8_MAX) interp->rare_events.name++; \
/* saturating add */ \
int val = FT_ATOMIC_LOAD_UINT8_RELAXED(interp->rare_events.name); \
if (val < UINT8_MAX) { \
FT_ATOMIC_STORE_UINT8_RELAXED(interp->rare_events.name, val+1); \
} \
RARE_EVENT_STAT_INC(name); \
} while (0); \

Expand Down
27 changes: 27 additions & 0 deletions Lib/test/test_free_threading/test_type.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import threading
import unittest

from concurrent.futures import ThreadPoolExecutor
Expand Down Expand Up @@ -95,6 +96,32 @@ def reader_func():

self.run_one(writer_func, reader_func)

def test___class___modification(self):
Comment thread
Fidget-Spinner marked this conversation as resolved.
Outdated
class Foo:
pass

class Bar:
pass

thing = Foo()
def work():
foo = thing
for _ in range(10000):
foo.__class__ = Bar
type(foo)
foo.__class__ = Foo
type(foo)


threads = []
for i in range(NTHREADS):
thread = threading.Thread(target=work)
thread.start()
threads.append(thread)

for thread in threads:
thread.join()

def run_one(self, writer_func, reader_func):
writer = Thread(target=writer_func)
readers = []
Expand Down