🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Differences between Semaphore and Mutex

#1319
From: Remy Lebeau (TeamB)
Date: Sun, 16 Sep 2007 19:11
34 lines
2012 bytes
"Danny" <danny2912@libero.it> wrote in message
news:46ed7265@newsgroups.borland.com...

> Fundamentally I have a TThread class, and when I close
> my application, the terminate event isn't come execute

Yes it will, if you use it properly.

> void __fastcall TFMain::FormClose(TObject *Sender, TCloseAction &Action)
> {
>     HANDLE h=CreateSemaphore(NULL,0,1,"PddSem");
>     Control->Terminate();
>     while(WaitForSingleObject(h,500)!=WAIT_OBJECT_0)
>       Application->ProcessMessages();
>     ::CloseHandle(h);
> }

You do not need a semaphore or mutex in that situation.  The
TThread::WaitFor() method works just fine in a form's OnClose event, ie:

    void __fastcall TFMain::FormClose(TObject *Sender, TCloseAction &Action)
    {
        Control->Terminate();
        Control->WaitFor();
    }

    void __fastcall TThreadControl::TerminateEvent(TObject *Sender)
    {
        .... my code .....
    }


Gambit
Technical Details
Message-ID: <46ed8016$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newspeer1.nwr.nac.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <46ecd663@newsgroups.borland.com> <kcaqe3d7a9ahqkl01dpp52rerc4g54o9et@4ax.com> <46ed637d$1@newsgroups.borland.com> <46ed7265@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,6b2ce248fe32d850
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: <46ecd663@newsgroups.borland.com> <kcaqe3d7a9ahqkl01dpp52rerc4g54o9et@4ax.com> <46ed637d$1@newsgroups.borland.com> <46ed7265@newsgroups.borland.com>
Subject: Re: Differences between Semaphore and Mutex
Date: Sun, 16 Sep 2007 12:11:24 -0700
Lines: 36
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.83.29.61
Message-ID: <46ed8016$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1189969942 75.83.29.61 (16 Sep 2007 12:12:22 -0700)
Path: arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newspeer1.nwr.nac.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
X-Original-Bytes: 1866