I thought an update might be in order, since it's a good example of the potential problems in multithreaded programming and might be useful to somebody.
I've got a procedure UnitSignal() called by multiple background threads, protected on entry by a critical section.
I've also got CheckUnitSignals() called by the main thread, which checks for queued asynchronous signals (i.e. that a signal should be raised a few mSec in the future).
CheckUnitSignals is protected by the same critical section, since it should obviously not run if another thread has already called UnitSignal().
But CheckUnitSignals() calls UnitSignal(), thus nesting critical section entry.
Specifically, on entry CheckUnitSignals() gets the critical section, then the nested re-get in UnitSignal() is ignored.
On exit UnitSignal() releases the critical section, leaving a short period during which CheckUnitSignals() still thinks it's protected, while in fact it's not.
I don't know whether this is the only issue but it's certainly something that I need to fix.
MarkMLl