[Issue 19956] Subclassing Thread with synchronized (this) may deadlock

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Jun 27 08:45:58 UTC 2019


https://issues.dlang.org/show_bug.cgi?id=19956

--- Comment #4 from anonymous4 <dfj1esp02 at sneakemail.com> ---
Recommended lock pattern in .net:

import core.thread;
import core.time;

class BadThread : Thread
{
    Object locker;
    this()
    {
        locker=new Object;
        super(&run);
    }
    void run()
    {
        synchronized (locker)
        {
            Thread.sleep(1.seconds);
            (new Thread({})).start;
        }
    }
}

--


More information about the Digitalmars-d-bugs mailing list