void operator delete(
_CrtMemBlockHeader * pHead;
RTCCALLBACK(_RTC_Free_hook, (pUserData, 0));
if (pUserData == NULL)
_mlock(_HEAP_LOCK); /* block other threads */ <--- Here it hangs !!!
/* get a pointer to memory block header */
pHead = pHdr(pUserData);
/* verify block type*/
_free_dbg( pUserData, pHead->nBlockUse );
_munlock(_HEAP_LOCK); /* release other threads */
If you'll kill a thread in the wrong moment after _mlock(_HEAP_LOCK) but before _munlock(_HEAP_LOCK) the next call of a function that uses _HEAP_LOCK will hang!
I've spent a lot of time to find this out...
Some more info:
Improving Performance with Thread-Private Heaps by Kevin Manley
Jochen Kalmbach writes in his blog about this problem also:
Why you should never call Suspend/TerminateThread (Part I)
Why you should never call Suspend/TerminateThread (Part II)