I'm not sure why this segfaults, since core.sync.mutex has an in contract to check for null? I am compiling in debug mode. import std.stdio; private Object mut;// = new Object(); void lockedFunction() { synchronized(mut) //I asume this makes does auto mutex = new Mutex(mut) and then mutex.lock()? { writefln("Whoops"); } //mutex.unlock();? /* Also results in segfault: auto mutex = new Mutex(mut); mutex.lock(); writefln("Whoops"); mutex.unlock(); */ } void main() { lockedFunction(); }
I can't reproduce this with either today's compiler or 2.064. In your code, you have: private Object mut;// = new Object(); Does that mean that you instantiate it somewhere? Because if it's not instantiated (i.e. your code is ran verbatim), it does result is a segmentation fault as you described, but only because the object used for locking is null. If you can still reproduce this today and can provide a complete test case, please reopen.
(In reply to Vladimir Panteleev from comment #1) > I can't reproduce this with either today's compiler or 2.064. > > In your code, you have: > > private Object mut;// = new Object(); > > Does that mean that you instantiate it somewhere? Because if it's not > instantiated (i.e. your code is ran verbatim), it does result is a > segmentation fault as you described, but only because the object used for > locking is null. > > If you can still reproduce this today and can provide a complete test case, > please reopen. The issue is that when compiled in debug mode, the "in" contract on core.sync.mutex is not checked. This should generate an exception detailing where the error was made when you try to synchronize on an uninitialized object, rather than a segfault (when in debug mode)
Commit pushed to master at https://github.com/dlang/druntime https://github.com/dlang/druntime/commit/a2ead6dd04efdfeb283b72daf167e85fe8db9c49 Fix issue 11594: Check if the monitor is null in _d_monitorenter In case of ``` synchronized (null) { // ... } ``` runtime will try to access __monitor field on a null, without checking if it's a null and it will segfault, leaving programmer clueless. https://issues.dlang.org/show_bug.cgi?id=11594
Oops, looks like I misunderstood the issue. Thanks for the clarification; and for the fix, Nemanja.
Commit pushed to newCTFE at https://github.com/dlang/druntime https://github.com/dlang/druntime/commit/a2ead6dd04efdfeb283b72daf167e85fe8db9c49 Fix issue 11594: Check if the monitor is null in _d_monitorenter
Commit pushed to stable at https://github.com/dlang/druntime https://github.com/dlang/druntime/commit/a2ead6dd04efdfeb283b72daf167e85fe8db9c49 Fix issue 11594: Check if the monitor is null in _d_monitorenter