Hey everyone. I've been trying to update threads by following Francois' directions, and I think I may have come across a bug. Can someone help me out here...
Why does the SYSLEVEL structure have a CRITICAL_SECTION inside it? Shouldn't a mutex be used instead?
According to MSDN, the function EnterCriticalSection has the following property:
If a thread terminates while it has ownership of a critical section, the state of the critical section is undefined.
Also, WaitForSingleObject returns WAIT_ABANDONED if:
the specified object is a mutex object that was not released by the thread that owned the mutex object before the owning thread terminated. Ownership of the mutex object is granted to the calling thread, and the mutex is set to nonsignaled.
So, if a thread _EnterSysLevel and is then terminated, no other threads can enter that sys level. This seems wrong to me...
Should I replace the CRITICAL_SECTION with a mutex? Any objections?
Or, should EnterCriticalSection be fixed so that it has similar behaviour to WaitForSingleObject, instead of "undefined" behaviour (which is currently to block forever)
Let me know what you guys think, Gregg Mattinson Co-op Developer Sun Microsystems of Canada
Gregg Mattinson gm138242@scot.canada.sun.com writes:
Why does the SYSLEVEL structure have a CRITICAL_SECTION inside it? Shouldn't a mutex be used instead?
No, a mutex is a lot slower, and there is no way for a SYSLEVEL to report that it was abandoned. If a thread gets killed while holding a critical section or syslevel, all bets are off anyway, since you don't know anything about the state of the resource that was protected by the critical section. There is simply no way to recover from that.