473,408 Members | 2,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Mutexes and WaitForSingleObject()

I have made the following main:

void main()
{
HANDLE myMutex = CreateMutex( NULL, false, NULL );

WaitForSingleObject(myMutex, INFINITE);
printf("should never appeared");
}

the program prints the messgae "should never appeared" and quit.
Is it not suppose to wait forever until myMutex will be released?

After running this program I have tried to change CreateMutex's second
argument into true but it had no affect.

thanks in advance,
Jul 22 '05 #1
4 13071
apparently you can't discuss windows programming in here, so go to
hell.

1. try naming the mutex, MSDN docs say that if the name conflicts with
anything it fails and returns ERROR_INVALID_HANDLE.
2. try checking to see if it returns ERROR_INVALID_HANDLE
3. make sure the mutex is "signalled". i've never used mutexs before so
i don't know how to do it.

Jul 22 '05 #2
GB
izik l wrote:
I have made the following main:

void main()
{
HANDLE myMutex = CreateMutex( NULL, false, NULL );

WaitForSingleObject(myMutex, INFINITE);
printf("should never appeared");
}

the program prints the messgae "should never appeared" and quit.
Is it not suppose to wait forever until myMutex will be released?

After running this program I have tried to change CreateMutex's second
argument into true but it had no affect.

thanks in advance,


Try checking the return value of both CreateMutex and
WaitForSingleObject to verify that they are not turning errors.

However, this is off-topic here (this group is for discussion of the C++
language, not OS-specific APIs, libraries, or tools), so if you still
have trouble, ask in a Windows newsgroup (e.g., something under
microsoft.public.*), not here.

Gregg
Jul 22 '05 #3
Mutex's dont block in same thread under windows :)... use critical
sections or events or whatever

Jul 22 '05 #4
rami wrote:
Mutex's dont block in same thread under windows :)... use critical
sections or events or whatever


Critical sections don't block in the same thread under Windows, either.
What would be the purpose of such a behavior, except to provide yet
another way to hang yourself?

--
Mike Smith
Jul 22 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: herbert | last post by:
Hi everybody; I've done 2 c++ class; server and client. I would like to make the same in c#. my waiting thread was waiting for 3 type of event: - a socket have data to read - a socket want...
4
by: Bill Sonia | last post by:
Hello, I have a Widnows Service that creates a system event that I would like to have a Sql Server stored procedure fire when the stored procedure is called. I have a Windows Service that runs...
6
by: Sean Kelly | last post by:
When both waiting on an event and a simple unnamed mutex, I'm wondering when WaitForSingleObject might return WAIT_FAILED. These are both execution paths I'd very much like to avoid exceptional...
5
by: ramialhasan | last post by:
If I have some c++ class exported from a Win32 dll, and from some other console application I created two threads and each thread creates an instance of the exported class. My question is...
1
by: Rachit | last post by:
Hi, I've a WebApp that calls Microsoft CRM WebServices to perform a particular action. In my WebApp I am spawning a new async thread for all the CRM related actions and sending the user to Thank...
2
by: UJ | last post by:
Is there a way to get a list of all the mutexes that have already been defined? TIA - Jeff.
2
by: Sasie7679 | last post by:
In one of our windows XP pro with service pack2 machine, the below API's fail. 1) MsgWaitForMultipleObjectsEx 2) MsgWaitForMultipleObjects 3) WaitforSingleObject 4) WaitforSingleObjectEx In...
10
by: blisspikle | last post by:
I see a lot of examples posted for Waitforsingleobject API for Processes or threads, but not events. I cannot get waitforsingleobject to subscribe to an event. I use a class PLCEthernet which is...
3
by: pbd22 | last post by:
Hi. I have a C# program that fires an external VB6 program which writes to a file and terminates. It is ugly, but this is how I have to do it. I cannot change this part of the program. The...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.