Hi Tim, 

Thanks for answering, I was allready looking for a VC6 CD to
install it and check it out.  I allready found VC5.0, but I still
have no idea where version 6.0 went. :-(  So this saves me some 
searching.
 
> static volatile long g_uModuleInitializing = 0; 
> static void start_initializing() 
> { 
>     while (InterlockedIncrement(&g_uModuleInitializing) != 1) { 
>         InterlockedDecrement(&g_uModuleInitializing); 
>     } 
> } 
> static void done_initializing() 
> { 
>     InterlockedDecrement(&g_uModuleInitializing); 
> } 
> 
> You can also use: 
> 
> #if _MSC_VER >= 1300 
> while (InterlockedCompareExchange(&g_uModuleInitializing, 1, 0)); 
> #else 
> while (InterlockedCompareExchange(((void 
> **)&g_uModuleInitializing, (void*)1, (void *) 0)); 
> #endif 
> 
> _MSC_VER is defined as 1200 for VC6 and 1300 for VC7. 
> 
> But this isn't necessarily reliable since it's OK to use VC6 
> (_MSC_VER == 1200) with the VC7 header files (which are 
> available separately as the platform SDK) - in fact I think 
> this is what I did when testing this coding. 

Do you know how to detect if the Platform SDKs are installed?
Another problem would be people who are not using MSVC,
but e.g. Borland, MinGW, CodeWarrior, etc.

So I think your first suggestion probably works better
accross compilers. I agree it is not that pretty, and busy
waiting in general is not so nice, but from what I understand
it only occurs during initialization and the chance of it 
happening in 2 threads at the same time is rather low.

Kind Regards,



Rob Lievaart

Reply via email to