1 /* Test that gettext() in multithreaded applications works correctly if
2 different threads operate in different locales with the same encoding.
3 Copyright (C) 2005-2024 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <https://www.gnu.org/licenses/>. */
27 /* Set to 1 if the program is not behaving correctly. */
30 /* Denotes which thread should run next. */
32 /* Lock and wait queue used to switch between the threads. */
34 pthread_cond_t waitqueue
;
36 /* Waits until the flipflop has a given value.
37 Before the call, the lock is unlocked. After the call, it is locked. */
41 if (pthread_mutex_lock (&lock
))
43 while (flipflop
!= value
)
44 if (pthread_cond_wait (&waitqueue
, &lock
))
48 /* Sets the flipflop to a given value.
49 Before the call, the lock is locked. After the call, it is unlocked. */
54 if (pthread_cond_signal (&waitqueue
))
56 if (pthread_mutex_unlock (&lock
))
61 thread1_execution (void *arg
)
66 uselocale (newlocale (LC_ALL_MASK
, "de_DE.ISO-8859-1", NULL
));
70 s
= gettext ("beauty");
72 if (strcmp (s
, "Sch\366nheit"))
74 fprintf (stderr
, "thread 1 call 1 returned: %s\n", s
);
80 s
= gettext ("beauty");
82 if (strcmp (s
, "Sch\366nheit"))
84 fprintf (stderr
, "thread 1 call 2 returned: %s\n", s
);
93 thread2_execution (void *arg
)
98 uselocale (newlocale (LC_ALL_MASK
, "fr_FR.ISO-8859-1", NULL
));
102 s
= gettext ("beauty");
104 if (strcmp (s
, "beaut\351"))
106 fprintf (stderr
, "thread 2 call 1 returned: %s\n", s
);
112 s
= gettext ("beauty");
114 if (strcmp (s
, "beaut\351"))
116 fprintf (stderr
, "thread 2 call 2 returned: %s\n", s
);
130 unsetenv ("LANGUAGE");
131 unsetenv ("OUTPUT_CHARSET");
132 textdomain ("multithread");
133 bindtextdomain ("multithread", OBJPFX
"domaindir");
137 if (pthread_mutex_init (&lock
, NULL
))
139 if (pthread_cond_init (&waitqueue
, NULL
))
141 if (pthread_create (&thread1
, NULL
, &thread1_execution
, NULL
))
143 if (pthread_create (&thread2
, NULL
, &thread2_execution
, NULL
))
145 if (pthread_join (thread2
, NULL
))