> Hmmm... I guess the process handle params of > DuplicateHandle() should have been my clue... so using an event handle > across multiple threads from the same process is perfectly safe? This > seems to differ from using, say, window handles across threads, which > is why I thought I would need duplication. I thought all handles were > similar in nature and thus required safe handling across threads even > within the same process.
IINM, you're wondering about what puzzles many when they first touch sync objects: "If it's not safe to share my object X, then I'll protect it with an event object. But, is it safe to share *that* event object across threads?" To which, the answer is, yes! If it were not, then you'd be going round and round, protecting each sync object with another one... Call it an infinite loop. :-) It's quite safe to share HANDLEs of events across threads, and for that matter, handles of mutexes, etc. except critical sections. This is how they're supposed to be used. Now, DuplicateHandle( ) actually creates a copy of the handle at kernel level, not at user level (which would be the same as creating a copy variable of it.) Its main usage is when you want to share HANDLEs across processes. And it's not because it's unsafe to share event handles across threads belonging to different processes, it's because the kernel maintains a kernel object table for each process, and the HANDLEs are plain indices through it; so, if you simply pass the numerical value of a HANDLE to another process, and it accesses it, it would be no different that passing a pointer to something in your address space to another, which would spell disaster. Feel free to ask more questions if you're still dizzy. I think it's important you get these topics well. ------------- Ehsan Akhgari Farda Technology (http://www.farda-tech.com/) List Owner: [email protected] [ Email: [EMAIL PROTECTED] ] [ WWW: http://www.beginthread.com/Ehsan ] That which an age feels to be evil is usually an untimely after-echo of that which was formerly felt to be good - the atavism of an older ideal. -Beyond Good And Evil, F. W. Nietzsche _______________________________________________ msvc mailing list [email protected] See http://beginthread.com/mailman/listinfo/msvc_beginthread.com for subscription changes, and list archive.
