Synchronized object must not be deleted. causes useless error message

BCS BCS at pathilink.com
Tue Nov 21 13:46:18 PST 2006


Frits van Bommel wrote:
> 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?

Except that I was testing to see what would happen in that case, I'm not 
sure I would have any clue what was wrong.


options (in no special order):

1> objects that are "locked" can't be deleted.

2> deleting a locked object, unlocks it. :b

3> some sane error message at either the delete or unlock
	Error: can't delete locked object.
	or
	Error: can't unlock deleted object.



problems:

#1

thread 1:
	synchronized(o)
		while(true){go = true;}

thread 2:
	go = false;
	while(!go){};
	delete o;	// fail

#2

threads 1-n competing on this:
	synchronized(o)
	{
		auto  a = o.getChild();
		wait();
		a.foo;	// more than one thread could get this
	}

thread 0:
	delete o;

#3
	what should it say?


Yes, it is a bug, but the error response is not good.



More information about the Digitalmars-d-bugs mailing list