1 /* Multithread-safety test for c_strtold().
2 Copyright (C) 2024 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 /* Written by Bruno Haible <bruno@clisp.org>, 2024. */
21 /* Work around GCC bug 44511. */
22 #if _GL_GNUC_PREREQ (4, 3)
23 # pragma GCC diagnostic ignored "-Wreturn-type"
26 #if USE_ISOC_THREADS || USE_POSIX_THREADS || USE_ISOC_AND_POSIX_THREADS || USE_WINDOWS_THREADS
37 #include "glthread/thread.h"
40 thread1_func (void *arg
)
42 const char input
[] = "1,5";
49 result
= c_strtold (input
, &ptr
);
50 if (!(result
== 1.0L && ptr
== input
+ 1 && errno
== 0))
52 fprintf (stderr
, "thread1 malfunction!\n"); fflush (stderr
);
61 thread2_func (void *arg
)
63 const char input
[] = "1,5";
70 result
= strtold (input
, &ptr
);
71 if (!(result
== 1.5L && ptr
== input
+ 3 && errno
== 0))
73 fprintf (stderr
, "thread2 disturbed by thread1!\n"); fflush (stderr
);
82 thread3_func (void *arg
)
87 sprintf (pointbuf
, "%#.0f", 1.0);
88 if (!(pointbuf
[1] == ','))
90 fprintf (stderr
, "thread3 disturbed by thread1!\n"); fflush (stderr
);
99 main (int argc
, char *argv
[])
101 /* Try to set the locale by implicitly looking at the LC_ALL environment
103 configure should already have checked that the locale is supported. */
104 if (setlocale (LC_ALL
, "") == NULL
)
107 /* Create the threads. */
108 gl_thread_create (thread1_func
, NULL
);
109 gl_thread_create (thread2_func
, NULL
);
110 gl_thread_create (thread3_func
, NULL
);
112 /* Let them run for 1 second. */
114 struct timespec duration
;
115 duration
.tv_sec
= (argc
> 1 ? atoi (argv
[1]) : 1);
116 duration
.tv_nsec
= 0;
118 nanosleep (&duration
, NULL
);
126 /* No multithreading available. */
133 fputs ("Skipping test: multithreading not enabled\n", stderr
);