Mutexes and WaitForSingleObject()

I

izik l

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,
 
K

kawahee

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

GB

izik said:
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
 
R

rami

Mutex's dont block in same thread under windows :)... use critical
sections or events or whatever
 
M

Mike Smith

rami said:
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?
 

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

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top