Bug 11594 – synchronized causing segfault instead of Error.
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
druntime
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-11-24T11:42:32Z
Last change time
2017-08-16T13:22:33Z
Assigned to
No Owner
Creator
Shammah Chancellor
Comments
Comment #0 by shammah.chancellor — 2013-11-24T11:42:32Z
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();
}
Comment #1 by dlang-bugzilla — 2017-07-05T19:01:47Z
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.
Comment #2 by shammah.chancellor — 2017-07-05T21:58:28Z
(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)
Comment #3 by github-bugzilla — 2017-07-06T10:51:41Z