News for hackers. Stuff that matters.
Re:Progress on No-GIL CPython by shrimpx on Monday October 23, 2023 @02:19AM (#37982181)
Thank you, I believe you are right. I did try to make a race condition happen using += and am having a hard time. Here's my code

    import threading

    i = 0

    def test():
        global i
        for x in range(1000000):
            i += 1


    threads = [threading.Thread(target=test) for t in range(20)]
    for t in threads:
        t.start()

    for t in threads:
        t.join()

    assert i == 20000000, i
Presumably the assert should fail sometimes but I haven't been able to observe that.

There are no comments on this comment yet.