Article View: borland.public.cppbuilder.nativeapi
Article #772Re: About the mutex...
From: Remy Lebeau (TeamB)
Date: Mon, 07 Jan 2008 17:54
Date: Mon, 07 Jan 2008 17:54
43 lines
2304 bytes
2304 bytes
"Robert Huang" <remmurds.bbs@ptt.cc> wrote in message
news:47817e00@newsgroups.borland.com...
> ReleaseMutex(Mutex);
That will not free the mutex. It will only release the lock that program A
may have on it. You need to use CloseHandle() to actually free the mutex.
> When A is running, the message "Already in running!!" will
> appear. But when A is terminated, the message will still appear.
Neither program A or B are closing their respective handles to the mutex.
All calls to Create/OpenMutex() must be balanced with equal calls to
CloseHandle(). Since program B is not closing its handle to the mutex, the
mutex remains alive after program A has terminated.
void __fastcall TBForm::ButtonExeClick(TObject *Sender)
{
HANDLE TargetMutex = OpenMutex(SYNCHRONIZE, FALSE, "Program-A");
if( !TargetMutex )
WinExec(ExeATitle.c_str(), SW_SHOW);
else
{
CloseHandle(TargetMutex); // <-- add this!
ShowMessage("Already in running!!");
}
}
__fastcall TAForm::TAForm(TComponent* Owner)
: TForm(Owner)
{
Mutex = CreateMutex(NULL, FALSE, "Program-A");
}
__fastcall TAForm::~TAForm()
{
CloseHandle(Mutex);
}
Gambit
Technical Details
Message-ID:
<478267cc$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!feeder1-2.proxad.net!proxad.net!feeder1-1.proxad.net!feeder.news-service.com!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<47817e00@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,34037fef0fe917a3 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: <47817e00@newsgroups.borland.com> Subject: Re: About the mutex... Date: Mon, 7 Jan 2008 09:54:50 -0800 Lines: 45 Organization: Lebeau Software 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.3198 X-RFC2646: Format=Flowed; Response NNTP-Posting-Host: 207.178.157.90 Message-ID: <478267cc$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1199728588 207.178.157.90 (7 Jan 2008 09:56:28 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!feeder1-2.proxad.net!proxad.net!feeder1-1.proxad.net!feeder.news-service.com!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail