mutex dead lock

Started by
4 comments, last by Xai 17 years, 10 months ago
seems my app is getting stuck in a mutex dead lock. And its being a pain the ass to debug. Now im rather new to multithreaded programming, when i create a mutex: mHandle = CreateMutex(0, false, 0); and lock it: WaitForSingleObject(mHandle, INFINITE); will this mutex only block if this handle has already been locked or will it also block if there is any other locked mutex?
Advertisement
When you wait for a given mutex (mHandle), your thread will be blocked only if some thread has already locked that specific mutex. As soon as that mutex is unlocked, the waiting thread will be resumed.

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

If you acquire the mutex multiple times in a single thread, though, you must release it an equal number of times.
"Walk not the trodden path, for it has borne it's burden." -John, Flying Monk
huh? how can it be acquired multiple times? i thought if you attempt to aquire a second time it blocks until the other frees it. Then obviously you will get a new lock which you must release when done...
You can acquire the same mutex twice in the same thread. Think about what would happen if this was not allowed, and the second attempt to acquire "blocks until the other frees it".
The only ways deadlock can be caused by using mutexes are:

1. You have some situation which acquires the mutex but never frees it.

2. You use more than 1 mutex, and you attempt to acquire them in inconsistent orders. (this is really just a special / common case of item 1).

This topic is closed to new replies.

Advertisement