These three patches add multithread-safety tests for the functions
c_strtof, c_strtod, c_strtold. And, sure enough, these tests fail,
due to the use of setlocale(), on
  - Solaris 11.3
  - mingw, MSVC 14
  - FreeBSD 5.2.1
They probably also fail on AIX (on systems which have a French locale
installed).


2024-03-05  Bruno Haible  <br...@clisp.org>

        c-strtold: Add multithread-safety test.
        * tests/test-c-strtold-mt.c: New file.
        * tests/test-c-strtold-mt.sh: New file, based on
        tests/test-c-strtold1.sh.
        * modules/c-strtold-tests (Files): Add them.
        (Depends-on): Add thread, nanosleep.
        (Makefile.am): Arrange to build test-c-strtold-mt and run
        test-c-strtold-mt.sh.

2024-03-05  Bruno Haible  <br...@clisp.org>

        c-strtod: Add multithread-safety test.
        * tests/test-c-strtod-mt.c: New file.
        * tests/test-c-strtod-mt.sh: New file, based on tests/test-c-strtod1.sh.
        * modules/c-strtod-tests (Files): Add them.
        (Depends-on): Add thread, nanosleep.
        (Makefile.am): Arrange to build test-c-strtod-mt and run
        test-c-strtod-mt.sh.

2024-03-05  Bruno Haible  <br...@clisp.org>

        c-strtof: Add multithread-safety test.
        * tests/test-c-strtof-mt.c: New file.
        * tests/test-c-strtof-mt.sh: New file, based on tests/test-c-strtof1.sh.
        * modules/c-strtof-tests (Files): Add them.
        (Depends-on): Add thread, nanosleep.
        (Makefile.am): Arrange to build test-c-strtof-mt and run
        test-c-strtof-mt.sh.

>From 890ed35c1ca4fbdeb002a4dd4f4bf87f28ee1fa7 Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Tue, 5 Mar 2024 13:42:27 +0100
Subject: [PATCH 1/3] c-strtof: Add multithread-safety test.

* tests/test-c-strtof-mt.c: New file.
* tests/test-c-strtof-mt.sh: New file, based on tests/test-c-strtof1.sh.
* modules/c-strtof-tests (Files): Add them.
(Depends-on): Add thread, nanosleep.
(Makefile.am): Arrange to build test-c-strtof-mt and run
test-c-strtof-mt.sh.
---
 ChangeLog                 |  10 +++
 modules/c-strtof-tests    |   9 ++-
 tests/test-c-strtof-mt.c  | 137 ++++++++++++++++++++++++++++++++++++++
 tests/test-c-strtof-mt.sh |  30 +++++++++
 4 files changed, 184 insertions(+), 2 deletions(-)
 create mode 100644 tests/test-c-strtof-mt.c
 create mode 100755 tests/test-c-strtof-mt.sh

diff --git a/ChangeLog b/ChangeLog
index 3e17d5ccc0..d755d15352 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2024-03-05  Bruno Haible  <br...@clisp.org>
+
+	c-strtof: Add multithread-safety test.
+	* tests/test-c-strtof-mt.c: New file.
+	* tests/test-c-strtof-mt.sh: New file, based on tests/test-c-strtof1.sh.
+	* modules/c-strtof-tests (Files): Add them.
+	(Depends-on): Add thread, nanosleep.
+	(Makefile.am): Arrange to build test-c-strtof-mt and run
+	test-c-strtof-mt.sh.
+
 2024-03-05  Bruno Haible  <br...@clisp.org>
 
 	locale-*.m4: Update comments.
diff --git a/modules/c-strtof-tests b/modules/c-strtof-tests
index c8f3dbfa3e..348ecb9a7c 100644
--- a/modules/c-strtof-tests
+++ b/modules/c-strtof-tests
@@ -3,6 +3,8 @@ tests/test-c-strtof.c
 tests/test-strtof.h
 tests/test-c-strtof1.sh
 tests/test-c-strtof1.c
+tests/test-c-strtof-mt.sh
+tests/test-c-strtof-mt.c
 tests/minus-zero.h
 tests/macros.h
 m4/locale-fr.m4
@@ -13,6 +15,8 @@ float
 isnanf-nolibm
 signbit
 setlocale
+thread
+nanosleep
 
 configure.ac:
 gt_LOCALE_FR
@@ -22,10 +26,11 @@ Makefile.am:
 TESTS += test-c-strtof
 check_PROGRAMS += test-c-strtof
 
-TESTS += test-c-strtof1.sh
+TESTS += test-c-strtof1.sh test-c-strtof-mt.sh
 TESTS_ENVIRONMENT += \
   LOCALE_FR='@LOCALE_FR@' \
   LOCALE_FR_UTF8='@LOCALE_FR_UTF8@' \
   LC_NUMERIC_IMPLEMENTED='@LC_NUMERIC_IMPLEMENTED@'
-check_PROGRAMS += test-c-strtof1
+check_PROGRAMS += test-c-strtof1 test-c-strtof-mt
 test_c_strtof1_LDADD = $(LDADD) $(SETLOCALE_LIB)
+test_c_strtof_mt_LDADD = $(LDADD) $(SETLOCALE_LIB) $(LIBMULTITHREAD) $(NANOSLEEP_LIB)
diff --git a/tests/test-c-strtof-mt.c b/tests/test-c-strtof-mt.c
new file mode 100644
index 0000000000..fc797f9a52
--- /dev/null
+++ b/tests/test-c-strtof-mt.c
@@ -0,0 +1,137 @@
+/* Multithread-safety test for c_strtof().
+   Copyright (C) 2024 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
+
+/* Written by Bruno Haible <br...@clisp.org>, 2024.  */
+
+#include <config.h>
+
+/* Work around GCC bug 44511.  */
+#if 4 < __GNUC__ + (3 <= __GNUC_MINOR__)
+# pragma GCC diagnostic ignored "-Wreturn-type"
+#endif
+
+#if USE_ISOC_THREADS || USE_POSIX_THREADS || USE_ISOC_AND_POSIX_THREADS || USE_WINDOWS_THREADS
+
+/* Specification.  */
+#include "c-strtod.h"
+
+#include <errno.h>
+#include <locale.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+
+#include "glthread/thread.h"
+
+static void *
+thread1_func (void *arg)
+{
+  const char input[] = "1,5";
+
+  for (;;)
+    {
+      char *ptr;
+      float result;
+      errno = 0;
+      result = c_strtof (input, &ptr);
+      if (!(result == 1.0f && ptr == input + 1 && errno == 0))
+        {
+          fprintf (stderr, "thread1 malfunction!\n"); fflush (stderr);
+          abort ();
+        }
+    }
+
+  /*NOTREACHED*/
+}
+
+static void *
+thread2_func (void *arg)
+{
+  const char input[] = "1,5";
+
+  for (;;)
+    {
+      char *ptr;
+      float result;
+      errno = 0;
+      result = strtof (input, &ptr);
+      if (!(result == 1.5f && ptr == input + 3 && errno == 0))
+        {
+          fprintf (stderr, "thread2 disturbed by thread1!\n"); fflush (stderr);
+          abort ();
+        }
+    }
+
+  /*NOTREACHED*/
+}
+
+static void *
+thread3_func (void *arg)
+{
+  for (;;)
+    {
+      char pointbuf[5];
+      sprintf (pointbuf, "%#.0f", 1.0);
+      if (!(pointbuf[1] == ','))
+        {
+          fprintf (stderr, "thread3 disturbed by thread1!\n"); fflush (stderr);
+          abort ();
+        }
+    }
+
+  /*NOTREACHED*/
+}
+
+int
+main (int argc, char *argv[])
+{
+  /* Try to set the locale by implicitly looking at the LC_ALL environment
+     variable.
+     configure should already have checked that the locale is supported.  */
+  if (setlocale (LC_ALL, "") == NULL)
+    return 1;
+
+  /* Create the threads.  */
+  gl_thread_create (thread1_func, NULL);
+  gl_thread_create (thread2_func, NULL);
+  gl_thread_create (thread3_func, NULL);
+
+  /* Let them run for 1 second.  */
+  {
+    struct timespec duration;
+    duration.tv_sec = (argc > 1 ? atoi (argv[1]) : 1);
+    duration.tv_nsec = 0;
+
+    nanosleep (&duration, NULL);
+  }
+
+  return 0;
+}
+
+#else
+
+/* No multithreading available.  */
+
+#include <stdio.h>
+
+int
+main ()
+{
+  fputs ("Skipping test: multithreading not enabled\n", stderr);
+  return 77;
+}
+
+#endif
diff --git a/tests/test-c-strtof-mt.sh b/tests/test-c-strtof-mt.sh
new file mode 100755
index 0000000000..27a647fcf2
--- /dev/null
+++ b/tests/test-c-strtof-mt.sh
@@ -0,0 +1,30 @@
+#!/bin/sh
+
+: "${LOCALE_FR=fr_FR}"
+: "${LOCALE_FR_UTF8=fr_FR.UTF-8}"
+
+if test $LOCALE_FR = none && test $LOCALE_FR_UTF8 = none; then
+  if test -f /usr/bin/localedef; then
+    echo "Skipping test: no locale for testing is installed"
+  else
+    echo "Skipping test: no locale for testing is supported"
+  fi
+  exit 77
+fi
+
+if $LC_NUMERIC_IMPLEMENTED; then
+  :
+else
+  echo "Skipping test: LC_NUMERIC category of locales is not implemented"
+  exit 77
+fi
+
+if test $LOCALE_FR != none; then
+  LC_ALL=$LOCALE_FR      ${CHECKER} ./test-c-strtof-mt${EXEEXT} || exit 1
+fi
+
+if test $LOCALE_FR_UTF8 != none; then
+  LC_ALL=$LOCALE_FR_UTF8 ${CHECKER} ./test-c-strtof-mt${EXEEXT} || exit 1
+fi
+
+exit 0
-- 
2.34.1

>From 289b043669bf9c20f072c325dd25ecba55be4da6 Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Tue, 5 Mar 2024 13:35:08 +0100
Subject: [PATCH 2/3] c-strtod: Add multithread-safety test.

* tests/test-c-strtod-mt.c: New file.
* tests/test-c-strtod-mt.sh: New file, based on tests/test-c-strtod1.sh.
* modules/c-strtod-tests (Files): Add them.
(Depends-on): Add thread, nanosleep.
(Makefile.am): Arrange to build test-c-strtod-mt and run
test-c-strtod-mt.sh.
---
 ChangeLog                 |  10 +++
 modules/c-strtod-tests    |   9 ++-
 tests/test-c-strtod-mt.c  | 137 ++++++++++++++++++++++++++++++++++++++
 tests/test-c-strtod-mt.sh |  30 +++++++++
 4 files changed, 184 insertions(+), 2 deletions(-)
 create mode 100644 tests/test-c-strtod-mt.c
 create mode 100755 tests/test-c-strtod-mt.sh

diff --git a/ChangeLog b/ChangeLog
index d755d15352..9c54b618c3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2024-03-05  Bruno Haible  <br...@clisp.org>
+
+	c-strtod: Add multithread-safety test.
+	* tests/test-c-strtod-mt.c: New file.
+	* tests/test-c-strtod-mt.sh: New file, based on tests/test-c-strtod1.sh.
+	* modules/c-strtod-tests (Files): Add them.
+	(Depends-on): Add thread, nanosleep.
+	(Makefile.am): Arrange to build test-c-strtod-mt and run
+	test-c-strtod-mt.sh.
+
 2024-03-05  Bruno Haible  <br...@clisp.org>
 
 	c-strtof: Add multithread-safety test.
diff --git a/modules/c-strtod-tests b/modules/c-strtod-tests
index d5cbbd8198..0c70a36803 100644
--- a/modules/c-strtod-tests
+++ b/modules/c-strtod-tests
@@ -3,6 +3,8 @@ tests/test-c-strtod.c
 tests/test-strtod.h
 tests/test-c-strtod1.sh
 tests/test-c-strtod1.c
+tests/test-c-strtod-mt.sh
+tests/test-c-strtod-mt.c
 tests/minus-zero.h
 tests/macros.h
 m4/locale-fr.m4
@@ -13,6 +15,8 @@ float
 isnand-nolibm
 signbit
 setlocale
+thread
+nanosleep
 
 configure.ac:
 gt_LOCALE_FR
@@ -22,10 +26,11 @@ Makefile.am:
 TESTS += test-c-strtod
 check_PROGRAMS += test-c-strtod
 
-TESTS += test-c-strtod1.sh
+TESTS += test-c-strtod1.sh test-c-strtod-mt.sh
 TESTS_ENVIRONMENT += \
   LOCALE_FR='@LOCALE_FR@' \
   LOCALE_FR_UTF8='@LOCALE_FR_UTF8@' \
   LC_NUMERIC_IMPLEMENTED='@LC_NUMERIC_IMPLEMENTED@'
-check_PROGRAMS += test-c-strtod1
+check_PROGRAMS += test-c-strtod1 test-c-strtod-mt
 test_c_strtod1_LDADD = $(LDADD) $(SETLOCALE_LIB)
+test_c_strtod_mt_LDADD = $(LDADD) $(SETLOCALE_LIB) $(LIBMULTITHREAD) $(NANOSLEEP_LIB)
diff --git a/tests/test-c-strtod-mt.c b/tests/test-c-strtod-mt.c
new file mode 100644
index 0000000000..f900014a20
--- /dev/null
+++ b/tests/test-c-strtod-mt.c
@@ -0,0 +1,137 @@
+/* Multithread-safety test for c_strtod().
+   Copyright (C) 2024 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
+
+/* Written by Bruno Haible <br...@clisp.org>, 2024.  */
+
+#include <config.h>
+
+/* Work around GCC bug 44511.  */
+#if 4 < __GNUC__ + (3 <= __GNUC_MINOR__)
+# pragma GCC diagnostic ignored "-Wreturn-type"
+#endif
+
+#if USE_ISOC_THREADS || USE_POSIX_THREADS || USE_ISOC_AND_POSIX_THREADS || USE_WINDOWS_THREADS
+
+/* Specification.  */
+#include "c-strtod.h"
+
+#include <errno.h>
+#include <locale.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+
+#include "glthread/thread.h"
+
+static void *
+thread1_func (void *arg)
+{
+  const char input[] = "1,5";
+
+  for (;;)
+    {
+      char *ptr;
+      double result;
+      errno = 0;
+      result = c_strtod (input, &ptr);
+      if (!(result == 1.0 && ptr == input + 1 && errno == 0))
+        {
+          fprintf (stderr, "thread1 malfunction!\n"); fflush (stderr);
+          abort ();
+        }
+    }
+
+  /*NOTREACHED*/
+}
+
+static void *
+thread2_func (void *arg)
+{
+  const char input[] = "1,5";
+
+  for (;;)
+    {
+      char *ptr;
+      double result;
+      errno = 0;
+      result = strtod (input, &ptr);
+      if (!(result == 1.5 && ptr == input + 3 && errno == 0))
+        {
+          fprintf (stderr, "thread2 disturbed by thread1!\n"); fflush (stderr);
+          abort ();
+        }
+    }
+
+  /*NOTREACHED*/
+}
+
+static void *
+thread3_func (void *arg)
+{
+  for (;;)
+    {
+      char pointbuf[5];
+      sprintf (pointbuf, "%#.0f", 1.0);
+      if (!(pointbuf[1] == ','))
+        {
+          fprintf (stderr, "thread3 disturbed by thread1!\n"); fflush (stderr);
+          abort ();
+        }
+    }
+
+  /*NOTREACHED*/
+}
+
+int
+main (int argc, char *argv[])
+{
+  /* Try to set the locale by implicitly looking at the LC_ALL environment
+     variable.
+     configure should already have checked that the locale is supported.  */
+  if (setlocale (LC_ALL, "") == NULL)
+    return 1;
+
+  /* Create the threads.  */
+  gl_thread_create (thread1_func, NULL);
+  gl_thread_create (thread2_func, NULL);
+  gl_thread_create (thread3_func, NULL);
+
+  /* Let them run for 1 second.  */
+  {
+    struct timespec duration;
+    duration.tv_sec = (argc > 1 ? atoi (argv[1]) : 1);
+    duration.tv_nsec = 0;
+
+    nanosleep (&duration, NULL);
+  }
+
+  return 0;
+}
+
+#else
+
+/* No multithreading available.  */
+
+#include <stdio.h>
+
+int
+main ()
+{
+  fputs ("Skipping test: multithreading not enabled\n", stderr);
+  return 77;
+}
+
+#endif
diff --git a/tests/test-c-strtod-mt.sh b/tests/test-c-strtod-mt.sh
new file mode 100755
index 0000000000..8c0e6e9006
--- /dev/null
+++ b/tests/test-c-strtod-mt.sh
@@ -0,0 +1,30 @@
+#!/bin/sh
+
+: "${LOCALE_FR=fr_FR}"
+: "${LOCALE_FR_UTF8=fr_FR.UTF-8}"
+
+if test $LOCALE_FR = none && test $LOCALE_FR_UTF8 = none; then
+  if test -f /usr/bin/localedef; then
+    echo "Skipping test: no locale for testing is installed"
+  else
+    echo "Skipping test: no locale for testing is supported"
+  fi
+  exit 77
+fi
+
+if $LC_NUMERIC_IMPLEMENTED; then
+  :
+else
+  echo "Skipping test: LC_NUMERIC category of locales is not implemented"
+  exit 77
+fi
+
+if test $LOCALE_FR != none; then
+  LC_ALL=$LOCALE_FR      ${CHECKER} ./test-c-strtod-mt${EXEEXT} || exit 1
+fi
+
+if test $LOCALE_FR_UTF8 != none; then
+  LC_ALL=$LOCALE_FR_UTF8 ${CHECKER} ./test-c-strtod-mt${EXEEXT} || exit 1
+fi
+
+exit 0
-- 
2.34.1

>From 8eaecd9d8b9ef6ab8df15ca5c880948a42484c9a Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Tue, 5 Mar 2024 13:44:13 +0100
Subject: [PATCH 3/3] c-strtold: Add multithread-safety test.

* tests/test-c-strtold-mt.c: New file.
* tests/test-c-strtold-mt.sh: New file, based on
tests/test-c-strtold1.sh.
* modules/c-strtold-tests (Files): Add them.
(Depends-on): Add thread, nanosleep.
(Makefile.am): Arrange to build test-c-strtold-mt and run
test-c-strtold-mt.sh.
---
 ChangeLog                  |  11 +++
 modules/c-strtold-tests    |   9 ++-
 tests/test-c-strtold-mt.c  | 137 +++++++++++++++++++++++++++++++++++++
 tests/test-c-strtold-mt.sh |  30 ++++++++
 4 files changed, 185 insertions(+), 2 deletions(-)
 create mode 100644 tests/test-c-strtold-mt.c
 create mode 100755 tests/test-c-strtold-mt.sh

diff --git a/ChangeLog b/ChangeLog
index 9c54b618c3..02489c3ce4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2024-03-05  Bruno Haible  <br...@clisp.org>
+
+	c-strtold: Add multithread-safety test.
+	* tests/test-c-strtold-mt.c: New file.
+	* tests/test-c-strtold-mt.sh: New file, based on
+	tests/test-c-strtold1.sh.
+	* modules/c-strtold-tests (Files): Add them.
+	(Depends-on): Add thread, nanosleep.
+	(Makefile.am): Arrange to build test-c-strtold-mt and run
+	test-c-strtold-mt.sh.
+
 2024-03-05  Bruno Haible  <br...@clisp.org>
 
 	c-strtod: Add multithread-safety test.
diff --git a/modules/c-strtold-tests b/modules/c-strtold-tests
index 9eff4dde43..7686da9755 100644
--- a/modules/c-strtold-tests
+++ b/modules/c-strtold-tests
@@ -3,6 +3,8 @@ tests/test-c-strtold.c
 tests/test-strtold.h
 tests/test-c-strtold1.sh
 tests/test-c-strtold1.c
+tests/test-c-strtold-mt.sh
+tests/test-c-strtold-mt.c
 tests/minus-zero.h
 tests/macros.h
 m4/locale-fr.m4
@@ -13,6 +15,8 @@ float
 isnanl-nolibm
 signbit
 setlocale
+thread
+nanosleep
 
 configure.ac:
 gt_LOCALE_FR
@@ -22,10 +26,11 @@ Makefile.am:
 TESTS += test-c-strtold
 check_PROGRAMS += test-c-strtold
 
-TESTS += test-c-strtold1.sh
+TESTS += test-c-strtold1.sh test-c-strtold-mt.sh
 TESTS_ENVIRONMENT += \
   LOCALE_FR='@LOCALE_FR@' \
   LOCALE_FR_UTF8='@LOCALE_FR_UTF8@' \
   LC_NUMERIC_IMPLEMENTED='@LC_NUMERIC_IMPLEMENTED@'
-check_PROGRAMS += test-c-strtold1
+check_PROGRAMS += test-c-strtold1 test-c-strtold-mt
 test_c_strtold1_LDADD = $(LDADD) $(SETLOCALE_LIB)
+test_c_strtold_mt_LDADD = $(LDADD) $(SETLOCALE_LIB) $(LIBMULTITHREAD) $(NANOSLEEP_LIB)
diff --git a/tests/test-c-strtold-mt.c b/tests/test-c-strtold-mt.c
new file mode 100644
index 0000000000..0b48eb8bfc
--- /dev/null
+++ b/tests/test-c-strtold-mt.c
@@ -0,0 +1,137 @@
+/* Multithread-safety test for c_strtold().
+   Copyright (C) 2024 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
+
+/* Written by Bruno Haible <br...@clisp.org>, 2024.  */
+
+#include <config.h>
+
+/* Work around GCC bug 44511.  */
+#if 4 < __GNUC__ + (3 <= __GNUC_MINOR__)
+# pragma GCC diagnostic ignored "-Wreturn-type"
+#endif
+
+#if USE_ISOC_THREADS || USE_POSIX_THREADS || USE_ISOC_AND_POSIX_THREADS || USE_WINDOWS_THREADS
+
+/* Specification.  */
+#include "c-strtod.h"
+
+#include <errno.h>
+#include <locale.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+
+#include "glthread/thread.h"
+
+static void *
+thread1_func (void *arg)
+{
+  const char input[] = "1,5";
+
+  for (;;)
+    {
+      char *ptr;
+      long double result;
+      errno = 0;
+      result = c_strtold (input, &ptr);
+      if (!(result == 1.0L && ptr == input + 1 && errno == 0))
+        {
+          fprintf (stderr, "thread1 malfunction!\n"); fflush (stderr);
+          abort ();
+        }
+    }
+
+  /*NOTREACHED*/
+}
+
+static void *
+thread2_func (void *arg)
+{
+  const char input[] = "1,5";
+
+  for (;;)
+    {
+      char *ptr;
+      long double result;
+      errno = 0;
+      result = strtold (input, &ptr);
+      if (!(result == 1.5L && ptr == input + 3 && errno == 0))
+        {
+          fprintf (stderr, "thread2 disturbed by thread1!\n"); fflush (stderr);
+          abort ();
+        }
+    }
+
+  /*NOTREACHED*/
+}
+
+static void *
+thread3_func (void *arg)
+{
+  for (;;)
+    {
+      char pointbuf[5];
+      sprintf (pointbuf, "%#.0f", 1.0);
+      if (!(pointbuf[1] == ','))
+        {
+          fprintf (stderr, "thread3 disturbed by thread1!\n"); fflush (stderr);
+          abort ();
+        }
+    }
+
+  /*NOTREACHED*/
+}
+
+int
+main (int argc, char *argv[])
+{
+  /* Try to set the locale by implicitly looking at the LC_ALL environment
+     variable.
+     configure should already have checked that the locale is supported.  */
+  if (setlocale (LC_ALL, "") == NULL)
+    return 1;
+
+  /* Create the threads.  */
+  gl_thread_create (thread1_func, NULL);
+  gl_thread_create (thread2_func, NULL);
+  gl_thread_create (thread3_func, NULL);
+
+  /* Let them run for 1 second.  */
+  {
+    struct timespec duration;
+    duration.tv_sec = (argc > 1 ? atoi (argv[1]) : 1);
+    duration.tv_nsec = 0;
+
+    nanosleep (&duration, NULL);
+  }
+
+  return 0;
+}
+
+#else
+
+/* No multithreading available.  */
+
+#include <stdio.h>
+
+int
+main ()
+{
+  fputs ("Skipping test: multithreading not enabled\n", stderr);
+  return 77;
+}
+
+#endif
diff --git a/tests/test-c-strtold-mt.sh b/tests/test-c-strtold-mt.sh
new file mode 100755
index 0000000000..7983587693
--- /dev/null
+++ b/tests/test-c-strtold-mt.sh
@@ -0,0 +1,30 @@
+#!/bin/sh
+
+: "${LOCALE_FR=fr_FR}"
+: "${LOCALE_FR_UTF8=fr_FR.UTF-8}"
+
+if test $LOCALE_FR = none && test $LOCALE_FR_UTF8 = none; then
+  if test -f /usr/bin/localedef; then
+    echo "Skipping test: no locale for testing is installed"
+  else
+    echo "Skipping test: no locale for testing is supported"
+  fi
+  exit 77
+fi
+
+if $LC_NUMERIC_IMPLEMENTED; then
+  :
+else
+  echo "Skipping test: LC_NUMERIC category of locales is not implemented"
+  exit 77
+fi
+
+if test $LOCALE_FR != none; then
+  LC_ALL=$LOCALE_FR      ${CHECKER} ./test-c-strtold-mt${EXEEXT} || exit 1
+fi
+
+if test $LOCALE_FR_UTF8 != none; then
+  LC_ALL=$LOCALE_FR_UTF8 ${CHECKER} ./test-c-strtold-mt${EXEEXT} || exit 1
+fi
+
+exit 0
-- 
2.34.1

Reply via email to