Re: WaitForSingleObject() will not deadlock

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Actually I'm quite expert in posix threads (and associated
synchronization primitives). I'm just new to the Windows world. As I
said in another post, the code example shown is obviously not useful
and so it should have been obvious that it was a simplification to
get to the heart of the matter.

On Sat, 30 Jun 2007 23:06:51 -0400 Joseph M. Newcomer <newcomer@xxxxxxxxxxxx> wrote:
Mutexes are not autoreset or manual reset; you are confusing them with events.

The OP is clueless about synchronization. All solutions relating to using mutexes,
semaphores, or events will be incorrect answers to his problem.
joe

On Sat, 30 Jun 2007 23:39:48 +0800, ajk <ak@xxxxxxxxxxxx> wrote:

On Sat, 30 Jun 2007 00:31:03 -0700, Frank Cusack <fcusack@xxxxxxxxxxx>
wrote:

Code like this

if (WaitForSingleObject(mutex, INFINITE) == WAIT_OBJECT_0)
AfxMessageBox("acquired", ID_OK);
if (WaitForSingleObject(mutex, INFINITE) == WAIT_OBJECT_0)
AfxMessageBox("acquired", ID_OK);

displays 2 alert boxes. How do I make this deadlock instead?

-frank

how did you create your mutex? was it autoreset or manual (my bet).

if you want to "deadlock" you need to call it from two threads, not
after each other - probably what is happening, once the mutex signaled
both WaitForSingleObject fires.
Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.