Mutex and WAIT_ABANDONED

W

William Stacey

..Net's Mutex object seems to ignore (or internally consume) a WAIT_ABANDONED
condition if the owning thread is aborted. The next thread waiting on the
Mutex gets the mutex with no error. If this is by design, it would seem to
be a dangerous design choice. Normally another thread would want to know
this information as the thing the mutex was protecting could (and probably
is) be in an inconsistant state, yet the 2nd thread will march on like
nothing was wrong. Am I missing something?
 
T

Tian Min Huang

Hello William,

Thanks for your post. As I understand, you want to know how to receive
WAIT_ABANDONED when the os detects a mutex owner's termination/exit. Please
correct me if there is any misunderstanding.

Based on my experience and research, the WAIT_ABANDONED is consumed by the
Wait methods of WaitHandle class in .NET. To work around the problem, you
can call WaitForSingleObject() instead.

WaitForSingleObject
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/bas
e/waitforsingleobject.asp

Please feel free to let me know if you have any problems or concerns.

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
W

William Stacey

Thank you Tian for your reply. I understand about the Win32 call, that is
how I knew about the wait_abandoned return code and how I tested that .Net's
wait seems to ignore it. I suppose I was making more of a statement that
that behavior is dangerous to folks who use the .Net mutex in with multiple
threads. If your lucky, you get some kind of exception, if your not, your
program keeps running with strange results. Its probably one in a million,
but that can happen daily or more. I guess I am saying they may want to
change that in next version and throw an exception. Thanks again. Cheers.
 
T

Tian Min Huang

Hi William,

Thanks for your feedback and I will report it to our Developer Team.

Have a nice day!

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top