Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

WaitForSingleObject return WAIT_ABANDONED, and no thread own it

Posted on 2001-09-03
11
Medium Priority
?
3,029 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 260 total points
ID: 6450552
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 260 total points
ID: 6450591
i.e. the first thread did not release the mutex before terminating.
0
 

Author Comment

by:Itay
ID: 6450862
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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
LVL 7

Expert Comment

by:peterchen092700
ID: 6450891
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
 
LVL 86

Expert Comment

by:jkr
ID: 6450902
>>Mutexes belong to the session

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

Author Comment

by:Itay
ID: 6450999
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
ID: 6451354
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
ID: 6467737
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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
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…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…

916 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