Article View: borland.public.cppbuilder.nativeapi
Article #3240Re: WaitForMulipleObjects function
From: mauro russo
Date: Mon, 07 Aug 2006 16:04
Date: Mon, 07 Aug 2006 16:04
164 lines
5633 bytes
5633 bytes
In the description of WaitforMultipleObjects
ther'is written nothing about Code Errors when fails.
Also the description of GetLastError reads
"For a complete list of error codes, see the WINNT.H header file in the
Win32 SDK."
I opened it but i didn't find anything listed as "code errors"
(i opened at the path C:\Programs\Borland\CBuilder6\Include\, that's
($BCB6)\Include )
I just found the constant SECURITY_SERVICE_RID with value 06L (i remember
you that 6 is
the value that GetLastError returns me).
Again, if i try to launch the same code (i posted in the precedent message
news:44d707a0@newsgroups.borland.com)
disablind "th1" (and disabling the waiting of the event by "th2"), the
thread "th2" can normally
acquires the first mutex whitout problems.
Some of you have same idea about the cause of the error descripted in the
message posted news:44d707a0@newsgroups.borland.com ?
Thank you,
Mauro.
"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:
<44d764ad$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!news1.google.com!news.germany.com!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<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:04:30 +0200 Lines: 166 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: <44d764ad$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1154966701 217.20.0.176 (7 Aug 2006 09:05:01 -0700) Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!news1.google.com!news.germany.com!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail