Search code examples
winapicreatethread

Using Win32 Event Objects


Noob question:

This link shows an example of CreateEvent and CreateThread

http://msdn.microsoft.com/en-us/library/ms686915(v=vs.85).aspx

My question is if the ThreadProc is truly thread safe?

Specifically, the dwWaitResult variable. Since all threads are waiting on the same event, it turns out this code works but had different events been created, for example, this would not work correct?


Solution

  • The dwWaitResult variable is a local variable in that function. Thus each individual thread has its own copy, which assures that the variable is thread safe. Each thread has its own stack, therefore all local variables are specific to the individual thread.