Re: DLL and synchronizing global data
I have a DLL that contains global data. The data is initialized from
DllMain
during DLL_PROCESS_ATTACH and destroyed during DLL_PROCESS_DETACH.
Once initialized, the global data is only read from and not modified
at all.
On top of Alex's explanation, I want to add that you have to be
careful about what you do in the DllMain function to prevent
deadlocks or access violations.
See MSDN for more info.
And on top of that, I'd add that calls to DllMain are serialized across
the entire process (regardless of the number of threads/processors/etc),
so there's no need to provide any synchronization during DllMain itself
either.
And on top of that again, I'd like to add that this is not strictly true.
This is only true when all dlls are linked implicitly.
It is possible for DllMain functions to become nested if you use LoadLibrary
within DllMain.
You really should not do this. MSDN even says so, but it is possible.
I just mention this because the MSDN documentation about DllMain is
inconsistent between MSDN versions, and not entirely correct in either
version.
--
Kind regards,
Bruno van Dooren
bruno_nos_pam_van_dooren@hotmail.com
Remove only "_nos_pam"