link-grammar-5.8.0/bindings/java-jni/jni-client.c
// Note that we do NOT offer any kind of protection from having
// another thread access the dictionary while this thread is still
// setting it up. It is up to the user to make sure that this thread
// (more generally, that all threads that call init) return before
// any of the threads call the parse functions.
//
// The only purpose of using the atomic_flag is to prevent two
// different threads from accidentally trying to initialize the
// dict at exactly the same time. (Which does seem like a reasonable
// guarantee to offer).
Note that we do NOT offer any kind of protection from having
another thread access the dictionary while this thread is still
setting it up. It is up to the user to make sure that this thread
(more generally, that all threads that call init) return before
any of the threads call the parse functions.

The only purpose of using the atomic_flag is to prevent two
different threads from accidentally trying to initialize the
dict at exactly the same time. (Which does seem like a reasonable
guarantee to offer).
Note that we do NOT offer any kind of protection from having another thread access the dictionary while this thread is still setting it up . It is up to the user to make sure that this thread ( more generally that all threads that call init ) return before any of the threads call the parse functions . The only purpose of using the atomic_flag is to prevent two different threads from accidentally trying to initialize the dict at exactly the same time . ( Which does seem like a reasonable guarantee to offer ) .
static void global_init(JNIEnv *env)
{
#ifdef HAVE_STDATOMIC_H
	if (atomic_flag_test_and_set(&dict_is_init)) return;
#else 
	if (dict_is_init) return;
	dict_is_init = true;
#endif 
#ifndef _WIN32
	const char *codeset;
	setlocale(LC_ALL, "");
	codeset = nl_langinfo(CODESET);
	if (!strstr(codeset, "UTF") && !strstr(codeset, "utf"))
	{
		prt_error("Warning: JNI: locale %s was not UTF-8; force-setting to en_US.UTF-8\n",
			codeset);
		setlocale(LC_CTYPE, "en_US.UTF-8");
	}
#endif 
	dict = dictionary_create_lang(in_language);
	if (!dict) throwException(env, "Error: unable to open dictionary");
	else do_test();
	const char *dict_version = linkgrammar_get_dict_version(dict);
	prt_error("Info: JNI: dictionary language '%s' version %s\n",
		in_language, dict_version);
}
static void global_init ( JNIEnv * env ) { #ifdef HAVE_STDATOMIC_H if ( atomic_flag_test_and_set ( & dict_is_init ) ) return ; #else if ( dict_is_init ) return ; dict_is_init = true ; #endif #ifndef _WIN32 const char * codeset ; setlocale ( LC_ALL , " " ) ; codeset = nl_langinfo ( CODESET ) ; if ( ! strstr ( codeset , " " ) && ! strstr ( codeset , " " ) ) { prt_error ( " \n " , codeset ) ; setlocale ( LC_CTYPE , " " ) ; } #endif dict = dictionary_create_lang ( in_language ) ; if ( ! dict ) throwException ( env , " " ) ; else do_test ( ) ; const char * dict_version = linkgrammar_get_dict_version ( dict ) ; prt_error ( " \n " , in_language , dict_version ) ; }
Note that we do NOT offer any kind of protection from having
another thread access the dictionary while this thread is still
setting it up.
Note that we do NOT offer any kind of protection from having another thread access the dictionary while this thread is still setting it up .
/* HAVE_STDATOMIC_H */ /* HAVE_STDATOMIC_H */ /* Get the locale from the environment...
	 * perhaps we should someday get it from the dictionary ??
	 */ /* Everything breaks if the locale is not UTF-8; check for this,
	 * and force  the issue !
	 */ // _WIN32