3 ?RCS: Copyright (c) 2017 Karl Williamson
5 ?RCS: You may distribute under the terms of either the GNU General Public
6 ?RCS: License or the Artistic License, as specified in the README file.
8 ?MAKE:d_thread_safe_nl_langinfo_l: Compile cat rm_try Oldconfig \
9 i_pthread i_stdlib i_string i_langinfo i_locale \
11 ?MAKE: -pick add $@ %<
12 ?S:d_thread_safe_nl_langinfo_l:
13 ?S: This variable contains the eventual value of the
14 ?S: HAS_THREAD_SAFE_NL_LANGINFO_L symbol, which indicates if the
15 ?S: nl_langinfo_l() function exists and is thread-safe.
17 ?C:HAS_THREAD_SAFE_NL_LANGINFO_L:
18 ?C: This symbol, when defined, indicates presence of the nl_langinfo_l()
19 ?C: function, and that it is thread-safe.
21 ?H:#$d_thread_safe_nl_langinfo_l HAS_THREAD_SAFE_NL_LANGINFO_L /**/
24 : check for thread_safe_nl_langinfo_l item
27 Checking to see if you have nl_langinfo_l() and that it is thread-safe
29 ?X: Despite claiming that nl_langinfo_l() is thread-safe, the POSIX 2008
30 ?X: standard allows for a non-safe implementation:
32 ?X: "nl_langinfo_l() uses an internal per-thread buffer, and nl_langinfo()
33 ?X: uses (in all threads) the same buffer that nl_langinfo_l() uses in the
34 ?X: initial thread. There can be interactions, but only when
35 ?X: nl_langinfo_l() is called in the initial thread"
37 ?X: If nl_langinfo_l() isn't thread safe, might as well just use plain
40 ?X: This program calls nl_langinfo_l(), then creates a thread, calling plain
41 ?X: nl_langinfo() from within it, then sees if the buffer in the original
42 ?X: thread was changed.
52 #$i_langinfo I_LANGINFO
54 # include <langinfo.h>
66 thread_start(void * arg)
68 nl_langinfo(RADIXCHAR);
73 char save_main_buffer[1000];
77 main_buffer = nl_langinfo_l(CODESET, newlocale(LC_ALL_MASK, "C", 0));
79 /* If too large for our generous allowance, just assume we don't have
81 if (strlen(main_buffer) >= sizeof(save_main_buffer)) {
85 strcpy(save_main_buffer, main_buffer);
87 if (pthread_attr_init(&attr) != 0) {
91 if (pthread_create(&subthread, &attr, thread_start, NULL) != 0) {
95 if (pthread_join(subthread, NULL) != 0) {
99 exit(! (strcmp(main_buffer, save_main_buffer) == 0));
102 case "$usethreads" in
105 if eval $compile; then
106 echo "Your system has nl_langinfo_l()..." >&4
108 echo "and it is thread-safe (just as I'd hoped)." >&4
109 d_thread_safe_nl_langinfo_l="$define"
110 echo "$d_thread_safe_nl_langinfo_l" >&4
112 echo "but it isn't thread-safe, so we won't use it." >&4
115 echo "your system does not have nl_langinfo_l()" >&4
118 *) echo "Since threads aren't selected, we won't bother looking for nl_langinfo_l()" >&4
120 if test X"$d_thread_safe_nl_langinfo_l" = X; then
121 d_thread_safe_nl_langinfo_l="$undef"