Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
Closed
Description
Bug report
Bug description:
Hi,
We're a research group focused on testing concurrent runtimes. Our work-in-progress prototype found that the current nogil build__str__ can return"{}" (empty dict) instead of the expected"set()" when there is a concurrentclear() operation. The program below shows the wrong behavior:
importthreadingimportsysdeft0(b1,s,res):b1.wait()s.clear()deft1(b1,s,res):b1.wait()res.append(s.__str__())defTest():s= {17,18,'a','b','c','d','e'}threads=[]barrier=threading.Barrier(2)res= []threads.append(threading.Thread(target=t0,args=(barrier,s,res)))threads.append(threading.Thread(target=t1,args=(barrier,s,res)))foriinrange(0,len(threads)):threads[i].start()foriinrange(0,len(threads)):threads[i].join()ifres[0]=="{}":print("found bug: "+res[0])print("test begin...")foriinrange(0,50000):threads= []ifi%1000==0:print(i)foriinrange(0,100):threads.append(threading.Thread(target=Test))fortinthreads:t.start()fortinthreads:t.join()print("test Done")
Sample output:
test begin...0found bug: {}found bug: {}found bug: {}found bug: {}found bug: {}found bug: {}found bug: {}found bug: {}found bug: {}found bug: {}found bug: {}found bug: {}found bug: {}found bug: {}found bug: {}found bug: {}found bug: {}found bug: {}This behavior can be observed quite readily. We tested it on a number of x86_64 and one ARM machine.
@flypoodles and@overlorde are part of the team, adding them so they get notified about further discussion.
CPython versions tested on:
3.14, CPython main branch
Operating systems tested on:
Linux