>I have a main thread and a worker thread. The main thread has called >CreateEvent() to create a handle that I want to signal once something >happens in the worker thread. > >Am I correct in saying that it is safe to, and in fact I must, duplicate >that handle for the worker thread and use the duplicate to call SetEvent() >from the worker thread?
It is safe to duplicate the handle.... ...But within a single process it is un-necessary. Either store the handle somewhere global (ugly but fine for small apps). Or pass the event handle to your thread procedure (along with all of its other arguments) in the LPVOID argument of the thread proc. >If not (i.e., if I try to call SetEvent() on the >original handle), I would cause a crash or violation of some sort? Nope this is fine. Normally you would only call DuplicateHandle to allow two processes to signal eachother. >Lifetime of app / handle usage: <snipped> > is this correct... Without knowing exactly what you are doing, and ignoring the un-needed duplication this seemed fine. Remember that you can just let a thread exit. When it does the thread handle becomes signalled. You can wait for this just as easily as an event. Of course this does mean that you will have to go through the procedure of starting up a new thread the next time you want one. Depending on how frequently you're going to be doing this you may find this wasteful of CPU resources. Daniel ___________________________________________________________ Book yourself something to look forward to in 2005. Cheap flights - http://www.tiscali.co.uk/travel/flights/ Bargain holidays - http://www.tiscali.co.uk/travel/holidays/ _______________________________________________ msvc mailing list [email protected] See http://beginthread.com/mailman/listinfo/msvc_beginthread.com for subscription changes, and list archive.
