Synchronized object must not be deleted. causes useless error message
Frits van Bommel
fvbommel at REMwOVExCAPSs.nl
Tue Nov 21 10:05:36 PST 2006
BCS wrote:
> this
>
> auto o = new Object;
> synchronized(o)
> delete o;
>
> causes a runtime error:
>
> Assertion failure: 'h->monitor" on line 99 in file 'internal\monitor.c'
So what would you prefer to happen?
Short version of the problem: because of the synchronized block you're
accessing a dangling pointer to o.
Long version: When you exit a synchronized block, it needs to unlock the
monitor associated with the object. I guess before the object is deleted
the monitor pointer is set to null (like the vtable pointer), which is a
good thing because otherwise you'd be accessing invalid memory without
knowing it.
You're still accessing invalid memory of course, since the monitor
pointer is now itself in invalid memory, but at least it's been detected
and you're told about it.
More information about the Digitalmars-d-bugs
mailing list