Article View: borland.public.cppbuilder.nativeapi
Article #1576Re: My Mutex stupidity - Help please
From: Remy Lebeau (TeamB)
Date: Tue, 17 Jul 2007 17:13
Date: Tue, 17 Jul 2007 17:13
36 lines
2288 bytes
2288 bytes
"static array?" <nospam@nospam.com> wrote in message
news:469cdda8@newsgroups.borland.com...
> What the heck is wrong with this. I expect to create a
> deadlock here - but it doesnt happen!
Why would you expect that? A thread is allowed to obtain a lock for a mutex
it already has a lock to, specifically so that it WON'T deadlock itself.
This is clearly stated in the documentation for CreateMutex():
"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."
> I expect that last call to never return - but it does immediately.
It is supposed to. The HANDLE values may be different, but they point to
the same physical mutex object. The thread already owns the mutex from the
first call to WaitForSingleObject(), so the second call exits immediately.
> I also note that a call to GetLastError does indeed return
> ALREADY_EXISTS....
It is supposed to. You passed the same name to both calls to CreateMutex().
> What am I doing wrong here?
Nothing at all. You simply are not reading the documentation. This
behavior is working as-designed.
Gambit
Technical Details
Message-ID:
<469cf8e1$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<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: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <469cdda8@newsgroups.borland.com> Subject: Re: My Mutex stupidity - Help please Date: Tue, 17 Jul 2007 10:13:54 -0700 Lines: 38 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1409 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 NNTP-Posting-Host: 75.82.252.126 Message-ID: <469cf8e1$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1184692449 75.82.252.126 (17 Jul 2007 10:14:09 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail