Thread overview
[Issue 11594] synchronized causing segfault instead of Error.
Oct 19, 2016
Nemanja Boric
Jul 05, 2017
Vladimir Panteleev
Jul 05, 2017
Shammah Chancellor
Jul 07, 2017
Vladimir Panteleev
October 19, 2016
https://issues.dlang.org/show_bug.cgi?id=11594

Nemanja Boric <4burgos@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |4burgos@gmail.com

--
July 05, 2017
https://issues.dlang.org/show_bug.cgi?id=11594

Vladimir Panteleev <dlang-bugzilla@thecybershadow.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |WORKSFORME

--- Comment #1 from Vladimir Panteleev <dlang-bugzilla@thecybershadow.net> ---
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.

--
July 05, 2017
https://issues.dlang.org/show_bug.cgi?id=11594

--- Comment #2 from Shammah Chancellor <shammah.chancellor@gmail.com> ---
(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)

--
July 06, 2017
https://issues.dlang.org/show_bug.cgi?id=11594

--- Comment #3 from github-bugzilla@puremagic.com ---
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

--
July 06, 2017
https://issues.dlang.org/show_bug.cgi?id=11594

github-bugzilla@puremagic.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|WORKSFORME                  |FIXED

--
July 07, 2017
https://issues.dlang.org/show_bug.cgi?id=11594

--- Comment #4 from Vladimir Panteleev <dlang-bugzilla@thecybershadow.net> ---
Oops, looks like I misunderstood the issue. Thanks for the clarification; and for the fix, Nemanja.

--
August 07, 2017
https://issues.dlang.org/show_bug.cgi?id=11594

--- Comment #5 from github-bugzilla@puremagic.com ---
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

--
August 16, 2017
https://issues.dlang.org/show_bug.cgi?id=11594

--- Comment #6 from github-bugzilla@puremagic.com ---
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

--