🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: WaitForMulipleObjects function

#3241
From: mauro russo
Date: Mon, 07 Aug 2006 16:34
150 lines
5124 bytes
Hi again!

I found that commenting the method Synchronize all worked correctly.
That call corrupted the stack and generated two not valid handles, so
the call to WaitForMultipleObjects of th2 generated error.

Well, ... removing the Synchronize call, i could see that
WaitForMultipleObjects,
with bWaitForAll = false, acquires ONLY ONE handle.

.... Thanks.


"mauro russo" <m.russo@uniplan.it> ha scritto nel messaggio
news:44d707a0@newsgroups.borland.com...
> Really i hoped you know already.
> However i build an easy test, but i'm having a weird (for me) result:
>
> That's the code:
>
>
>     HANDLE Handle_M1 = CreateMutex(NULL,false,"M1");
>     HANDLE Handle_M2 = CreateMutex(NULL,false,"M2");
>
>    HANDLE Handle_ev2 = CreateEvent(NULL,false,false,"ev2");
>
>    HANDLE Ms[2] = {Handle_M1,Handle_M2};
>
>    TThreadWMO *th1 = new TThreadWMO(true);
>    th1->EventToWaitAtBegin = NULL;
>    th1->EventToSignalAtEnd = Handle_ev2;
>    th1->MsToWait = Ms;
>    th1->NMsToWait = 2;
>    th1->Name = "th1";
>
>    TThreadWMO *th2 = new TThreadWMO(true);
>    th2->EventToWaitAtBegin = Handle_ev2;
>    th2->EventToSignalAtEnd = NULL;
>    th2->MsToWait = Ms;
>    th2->NMsToWait = 2;
>    th2->Name = "th2";
>
>    th1->Resume();
>    th2->Resume();
> }
>
> where:
>
> class TThreadWMO : public TThread
> {
> private:
> protected:
>    void __fastcall Execute();
>    String MsgToshow;
>    void __fastcall ShowMsg(void);
> public:
>    String Name;
>    HANDLE EventToWaitAtBegin,EventToSignalAtEnd;
>    CONST HANDLE *MsToWait;
>    unsigned int NMsToWait;
>    __fastcall TThreadWMO(bool CreateSuspended);
> };
>
> __fastcall TThreadWMO::TThreadWMO(bool CreateSuspended)
>    : TThread(CreateSuspended)
> {
>    EventToWaitAtBegin = EventToSignalAtEnd = NULL;
>    MsToWait = NULL;
>    NMsToWait = 0;
> }
>
> void __fastcall TThreadWMO::Execute()
> {
>    //---- Place thread code here ----
>    if (EventToWaitAtBegin != NULL)
>       WaitForSingleObject(EventToWaitAtBegin,INFINITE);
>
>    if (NMsToWait > 0){
>       DWORD w = WaitForMultipleObjects(NMsToWait,MsToWait,false,INFINITE);
> //waits at least one.
>       if (w == WAIT_TIMEOUT)
>          ...
>      else
>       if ( (w >= WAIT_OBJECT_0) & (w < WAIT_OBJECT_0 + NMsToWait) )
>         ...
>     else
>       if ( (w >= WAIT_ABANDONED_0) & (w < WAIT_ABANDONED_0 + NMsToWait) )
>          ...
>       else
>       if (w == WAIT_FAILED)
>          ...
>       else
>          ...
>    }
>
>    if (EventToSignalAtEnd != NULL)
>       SetEvent(EventToSignalAtEnd);
> }
>
> Well. For the thread "th1" the API WaitForMultipleObjects successes with w
=
> WAIT_OBJECT_0 (until here it's what we except and doesn't add anything to
> answer to my question).
> For the thread "th2", the API fails [w = WAIT_FAILED] and GetLastError()
> gets the value six (6).
>
> 1) What can make it failing??????
> 2) i couldn't answer to my initial question, because the API is for "th2"
is
> failing. I hoped to see w = WAIT_OBJECT_0+1.
>
> some help for me?
>
> Thank you.
>
> "Bob Gonder" <notbg@notmindspring.invalid> ha scritto nel messaggio
> news:prpcd2hj1di4dpm4uqun57ncaj7g69fkl9@4ax.com...
> > mauro russo wrote:
> >
> > >if i use the value FALSE  for  the bWaitAll parameter
> > >and more objects are signalled, i expect that the thread that
> > >called WaitForMultipleObjects acquires only one [that with the
> > >minimum index] of those objects.
> > >Is it like that?
> > >
> > >But i hope some of you can make me sure about my idea.
> >
> > Test it.
> >
> > #include <stdio.h>
> > #include <conio.h>
> > #include <windows.h>
> > int main(void)
> > { int i;
> > DWORD w;
> > HANDLE  Events[5];
> > for( i=0; i<5; ++i )
> > Events[i]=CreateEvent(NULL,FALSE,TRUE,NULL);
> > do{
> > w = WaitForMultipleObjects( 5, Events, FALSE, 1000 );
> > if( w >= WAIT_OBJECT_0 )
> > printf( "Event %i Reported\r\n", w-WAIT_OBJECT_0 );
> > }while( w !=WAIT_TIMEOUT );
> > getch();
> > return 0;
> > }
> >
> >
>
>
Technical Details
Message-ID: <44d76ba2@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <44d62a4a$1@newsgroups.borland.com> <prpcd2hj1di4dpm4uqun57ncaj7g69fkl9@4ax.com> <44d707a0@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,8747f5d210339525
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
Reply-To: "mauro russo" <m.russo@uniplan.it>
From: "mauro russo" <m.russo@uniplan.it>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <44d62a4a$1@newsgroups.borland.com> <prpcd2hj1di4dpm4uqun57ncaj7g69fkl9@4ax.com> <44d707a0@newsgroups.borland.com>
Subject: Re: WaitForMulipleObjects function
Date: Mon, 7 Aug 2006 18:34:11 +0200
Lines: 152
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
NNTP-Posting-Host: 217.20.0.176
Message-ID: <44d76ba2@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1154968482 217.20.0.176 (7 Aug 2006 09:34:42 -0700)
Path: arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail