🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Wait for "signal" from another application and/or thread

#8981
From: zoom
Date: Fri, 13 Aug 2004 14:26
108 lines
3899 bytes
How to make sure that each and every one of the waiting thread be signalled
?
(Note that we may be running multiple instances of the same application)
...
///////////////////////////////////////////////////////////////////////
TForm1 *Form1;
class TMyThread : public TThread
{
private:
  void __fastcall
SyncFunc(void){Form1->Memo1->Lines->Add(String().sprintf("%d %d
%s",FCount,FID,TimeToStr(Now()).c_str()));}
  void __fastcall Execute();
  int FCount,FID;
public:
  __fastcall TMyThread(bool CreateSuspended,int
ID):TThread(CreateSuspended){FID=ID;FCount=0;}
};
void __fastcall TMyThread::Execute()
{
  while (!Terminated){
    Sleep(rand() % 1000);
    BOOL WaitResult = (WaitForSingleObject(h1,INFINITE) == WAIT_OBJECT_0);
   /<<<< What to do on the following line so that every waiting thread be
signalled? >>>>
    if (WaitResult)   ResetEvent(h1);
    Synchronize(SyncFunc);
    FCount++;
  }
}

TMyThread *Th1, *Th2, *Th3;
HANDLE h1;
//--------------------------------------------------------------------------
-
__fastcall TForm1::TForm1(TComponent* Owner)
 : TForm(Owner)
{
  h1 = CreateEvent( NULL,TRUE,FALSE,"MyEventObject") ;
  Th1 = new TMyThread(false,1);
  Th2 = new TMyThread(false,2);
  Th3 = new TMyThread(false,3);
}
//--------------------------------------------------------------------------
-
void __fastcall TForm1::Button1Click(TObject *Sender)
{
   SetEvent(h1);
}
//--------------------------------------------------------------------------
-
void __fastcall TForm1::FormDestroy(TObject *Sender)
{
   Th1->Terminate();   Th2->Terminate();   Th3->Terminate();
   SetEvent(h1);
   delete Th1; delete Th2; delete Th3;
   CloseHandle(h1);
}
////////////////////////////////////////////////////////////////////////////
///////////////////


> <zoom> wrote in message news:4105617c$1@newsgroups.borland.com...
>
> >        while(!Terminated && !MYSIGNAL) {
> >             //?? How to implement following line ??
> >             wait for MYSIGNAL
> >            ...
> >        }
>
> Use OpenEvent() and WaitForSingleObject().
>
> >        while(!Terminated ) {
> >            if (Some Condition) {
> >               //?? How to implement following line ??
> >              raise  MYSIGNAL
> >           }
> >            ...
> >        }
>
> Use CreateEvent() and SetEvent().
>
> >        while(!Terminated && !MYSIGNAL) {
> >             //?? How to implement following line ??
> >             wait for MYSIGNAL for 200millisecond
> >              if (MYSIGNAL)
> >                 Do this..
> >              else
> >                 Do that..
> >            ...
> >        }
>
> Same as above.
>
> >        while(!Terminated ) {
> >            if (Some Condition) {
> >               //?? How to implement following line ??
> >              raise  MYSIGNAL
> >           }
> >            ...
> >        }
>
> Same as above.
>
>
> Gambit
>
>
Technical Details
Message-ID: <411ccf89@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.icl.net!colt.net!peernews3.colt.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <4105617c$1@newsgroups.borland.com> <4105777f$3@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,b6552239fe09c315
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: <zoom>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <4105617c$1@newsgroups.borland.com> <4105777f$3@newsgroups.borland.com>
Subject: Re: Wait for "signal" from another application and/or thread 
Date: Sat, 14 Aug 2004 00:26:16 +1000
Lines: 110
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1437
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441
NNTP-Posting-Host: 211.30.68.31
Message-ID: <411ccf89@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1092407177 211.30.68.31 (13 Aug 2004 07:26:17 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.icl.net!colt.net!peernews3.colt.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail