File tree Expand file tree Collapse file tree 1 file changed +9
-4
lines changed
src/native/libs/System.Native Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Original file line number Diff line number Diff line change @@ -57,13 +57,18 @@ void* SystemNative_GetDefaultSearchOrderPseudoHandle(void)
5757 return (void * )RTLD_DEFAULT ;
5858}
5959#else
60- static void * g_defaultSearchOrderPseudoHandle = NULL ;
60+ static void * volatile g_defaultSearchOrderPseudoHandle = NULL ;
6161void * SystemNative_GetDefaultSearchOrderPseudoHandle (void )
6262{
63- if (g_defaultSearchOrderPseudoHandle == NULL )
63+ // Read the value once from the volatile static to avoid reading from memory twice.
64+ void * defaultSearchOrderPseudoHandle = (void * )g_defaultSearchOrderPseudoHandle ;
65+ if (defaultSearchOrderPseudoHandle == NULL )
6466 {
65- g_defaultSearchOrderPseudoHandle = dlopen (NULL , RTLD_LAZY );
67+ // Assign back to the static as well as the local here.
68+ // We don't need to check for a race between two threads as the value returned by
69+ // dlopen here will always be the same in a given environment.
70+ g_defaultSearchOrderPseudoHandle = defaultSearchOrderPseudoHandle = dlopen (NULL , RTLD_LAZY );
6671 }
67- return g_defaultSearchOrderPseudoHandle ;
72+ return defaultSearchOrderPseudoHandle ;
6873}
6974#endif
You can’t perform that action at this time.
0 commit comments