🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #1575

Re: My Mutex stupidity - Help please

#1575
From: Bruce Salzman
Date: Tue, 17 Jul 2007 15:25
45 lines
2281 bytes
"static array?" <nospam@nospam.com> wrote in message 
news:469cdda8@newsgroups.borland.com...
>I was having issues with my mutex handler - and have boiled it down 
>to this.
>
> What the heck is wrong with this. I expect to create a deadlock 
> here - but it doesnt happen!
>
> char * c = "ksfgkjsfdgkj\0";
>
> HANDLE MutexHandle1 = CreateMutex(NULL, FALSE, c);
> WaitForSingleObject(MutexHandle1, INFINITE);
>
> // ok so I have the mutex lock now
>
> // lets try to create (open) the same mutex.  (I note that the 
> handle
> // address returned is different for each call).
>
> HANDLE MutexHandle2 = CreateMutex(NULL, FALSE, c); // note exact 
> same name
> WaitForSingleObject(MutexHandle2, INFINITE);
>
> // I expect that last call to never return - but it does 
> immediately.
> // I also note that a call to GetLastError does indeed return 
> ALREADY_EXISTS.... so I am confused...
>
> What am I doing wrong here?

From the Windows SDK:
"The thread that owns a mutex can specify the same mutex in repeated 
wait function calls without blocking its execution. Typically, you 
would not wait repeatedly for the same mutex, but this mechanism 
prevents a thread from deadlocking itself while waiting for a mutex 
that it already owns. However, to release its ownership, the thread 
must call ReleaseMutex once for each time that the mutex satisfied a 
wait."



-- 

Bruce
Technical Details
Message-ID: <469cdf56$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.germany.com!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <469cdda8@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,fca5f87658921108
X-Google-Attributes: gid10cc67,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
From: " Bruce Salzman" <bruce@nospam.org>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <469cdda8@newsgroups.borland.com>
Subject: Re: My Mutex stupidity - Help please
Date: Tue, 17 Jul 2007 10:25:12 -0500
Lines: 47
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.3138
X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2900.3138
X-RFC2646: Format=Flowed; Response
NNTP-Posting-Host: 67.52.3.150
Message-ID: <469cdf56$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1184685910 67.52.3.150 (17 Jul 2007 08:25:10 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.germany.com!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail