Solved

WaitForSingleObject return WAIT_ABANDONED, and no thread own it

Posted on 2001-09-03
11
2,861 Views
Last Modified: 2013-12-03
Hi,


The WaitForSingleObject return WAIT_ABANDONED.

The main thread owns it.
Two threads are using this mutex.  Each thread takes ownership on the
mutex  and release it for intermittently.
The first thread finishes its run(release the mutex) and exit with
code 0.
The second thread try to get the mutex.
The WAIT_ABANDONED return code recieved.  
If the test skipped the second thread get the mutex normally.

Can I skip this check?
What is the problem?

Thanks
0
Comment
Question by:Itay
  • 4
  • 2
  • 2
11 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 65 total points
Comment Utility
Value
WAIT_ABANDONED

Meaning
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.

It seems that your 2nd thread does not release the mutex before terminating...
0
 
LVL 7

Assisted Solution

by:peterchen092700
peterchen092700 earned 65 total points
Comment Utility
i.e. the first thread did not release the mutex before terminating.
0
 

Author Comment

by:Itay
Comment Utility
The two threads using object belongs to thread main.
This object has method that
1)    use WaitForSingleObject(handle, INFINIT)
2)    use Release(handle)

There is no chance that the mutex was not released.
0
 
LVL 7

Expert Comment

by:peterchen092700
Comment Utility
neither threads nor mutexes belong to a thread. Threads belong to a process. Mutexes belong to the session (I guess), *Handles to* Mutexes belong to a process.

Add TRACEs to where you create, acquire and release the handles, and check the return value of WaitForXXX and ReleaseMutex.

Peter





0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 86

Expert Comment

by:jkr
Comment Utility
>>Mutexes belong to the session

Mutexes are kerel objects, so they're just 'loaned'...
0
 

Author Comment

by:Itay
Comment Utility
Sure,
:-)

The mutex in its current initilaization belongs to the process.

I traced the program, the return code from ReleaseMutex is 1.
Its okay as far as i know, it shouldn't be zero.

The return code from WaitForSingleObject is 0.
After the thread was destroyed, it is 128.


0
 
LVL 7

Expert Comment

by:peterchen092700
Comment Utility
might sound a bit silly, but: did you count them? Remember that, for each successful wait for a mutex, there must be a releasemutex.

0
 
LVL 7

Expert Comment

by:peterchen092700
Comment Utility
an abandoned mutex (i.e. thread acquired mutex, and teminated without releasing the mutex) is the *only* reason for WAIT_ABANDONED to be returned. So you might understand we expect yu to double-check this...
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now