?
Solved

WaitForSingleObject return WAIT_ABANDONED, and no thread own it

Posted on 2001-09-03
11
Medium Priority
?
2,984 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

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!

Question has a verified solution.

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

In this article, I will show how to use the Ribbon IDs Tool Window to assign the built-in Office icons to a ribbon button.  This tool will help us to find the OfficeImageId that corresponds to our desired built-in Office icon. The tool is part of…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
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…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

770 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