Got a chance to read gynvael’s (http://gynvael.coldwind.pl) old article on multithread issue in dynamic initialization of static variable. You can read his article here http://gynvael.coldwind.pl/?id=406. Recently i was working in a project that uses Microsoft “Unified Event Model”. You can read about this here (http://msdn.microsoft.com/en-us/library/aa984511%28v=vs.71%29.aspx). You can read my previous blog on how this __hook() and __event() is working behind the screen (https://hiddencodes.wordpress.com/2011/10/20/understanding-__event-__hook-__unhook-event_source-event_receiver/). So what is the relation here ?
In both the cases we are talking about “compiler injected code”. In the first case we discussed about “compiler injected code” when we are dynamically initializing static variables. In the second case, we discussed about the underlying code to implement Microsoft “Unified Event Model”. If you closely audit the code injected by compiler then you will see the relation here.
Compiler injected code to implement Microsoft “Unified Event Model” is not thread safe ! Both the lock() and unlock() functions are just dummy.
The point is, in both the cases CL compiler injected code that is not thread safe. We should be auditing the codebase keeping this in mind.
Time for me to re-read “WYSINWYX: What You See Is Not What You eXecute” paper (www.cs.wisc.edu/wpis/papers/wysinwyx05.pdf)