Ptdomaine is quite right here.
This happens when the kernel plays APC with your threads.
This means everytime another process calls ReadProcessMemory (like any AV scan does), or SuspendThread / ResumeThread / CreateRemoteThread, or when an “hardware” interrupt happens (like unplugging a USB device you might be using), or the first time you call TlsAlloc and so on.
Sure, it doesn’t shows up 100% of the time, probably not even 0.1% of times, but it CAN happen, so that it’s a road I wouldn’t go on anyway.
BTW, if I know this, it’s because it happened in our main software (which runs 24/7), and the crash dump they send was unexplainable unless such behaviour occurs (a thread was still waiting for a signaled event while the main thread continued, making the main thread waiting for the other thread’s work and “jobDone” event which never happened => deadlock).
In all cases, you can do whatever you want…[/quote]