开发者

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, 开发者_StackOverflow社区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?


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.


The Event is created by name, so if the event is already created is reused in any other thread "creating" an event with the same name. As a result, the example code IS thread safe.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜