Re: Event Handle scope.

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Scott McPhillips [MVP] (scottmcp_at_mvps.org.nothere)
Date: 05/14/04


Date: Fri, 14 May 2004 08:01:06 -0500

Macca wrote:
> I have a thread that uses WaitForMultipleObjects. I have various events and was wondering whether the handles that represent the events (CONST HANDLE *lpHandles in WaitForMultipleObjects Function) need to be declared globally to the dialog class(i.e member variables of the dialog class) so that other functions in the dialog class can set those events. If i declare event handles local to the thread function that contains the WaitForMultipleObjects then all event handling would need to be done in this function. Is that correct or am i missing something?
>
> Cheers
> Macca

If you want to access the handles from the dialog and from the thread
function then they should be declared as member variables of the dialog
class, and initialized before creating the thread. Use the LPVOID
thread parameter to pass a pointer to the thread (such as the dialog's
'this' pointer) so it can access such shared variables.

If the thread also needs to create some private event handles then it
can declare a local array, copy the shared handles into it, and
initialize the local handles in the remainder of the array.

-- 
Scott McPhillips [VC++ MVP]


Relevant Pages

  • Re: About c++ pointer
    ... Here you declare a local array and initialise it to "Hello world". ... > char *GetString2 ... Here you declare a pointer which points to a constant static area containing ...
    (comp.lang.cpp)
  • Re: Shared Variable Question VB.NET 2003
    ... Thanks for the pointers, ... shared variables are initialized in each thread! ... It would be more typical to declare this as Private and control any ... external access via a Public property, ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Windows array allocation problem
    ... Steve Lionel wrote: ... This means that you cannot simply declare a large array in ... common or as a local array on an x64 system. ...
    (comp.lang.fortran)
  • Re: How to test for the existence of __func__?
    ... as a local array inside each function. ... So if you're lucky the ... compiler may not declare it outside the function, ... Of course it's non-portable to declare your own identifier ...
    (comp.lang.c)
  • Re: threads in perl
    ... >If you want to use shared variables, you must declare it as shared. ... >Watch out for Threads vs. threads capitalization errors. ...
    (comp.lang.perl.misc)