1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23: #include <libintl.h>
24: #include <locale.h>
25: #include <pthread.h>
26: #include <stdio.h>
27: #include <stdlib.h>
28: #include <string.h>
29:
30:
31: int result;
32:
33:
34: int flipflop;
35:
36: pthread_mutex_t lock;
37: pthread_cond_t waitqueue;
38:
39:
40:
41: static void
42: waitfor (int value)
43: {
44: if (pthread_mutex_lock (&lock))
45: exit (10);
46: while (flipflop != value)
47: if (pthread_cond_wait (&waitqueue, &lock))
48: exit (11);
49: }
50:
51:
52:
53: static void
54: setto (int value)
55: {
56: flipflop = value;
57: if (pthread_cond_signal (&waitqueue))
58: exit (20);
59: if (pthread_mutex_unlock (&lock))
60: exit (21);
61: }
62:
63: void *
64: thread1_execution (void *arg)
65: {
66: char *s;
67:
68: waitfor (1);
69: uselocale (newlocale (LC_ALL_MASK, "de_DE.ISO-8859-1", NULL));
70: setto (2);
71:
72:
73:
74: waitfor (1);
75: s = gettext ("cheese");
76: puts (s);
77: if (strcmp (s, "K\344se"))
78: {
79: fprintf (stderr, "thread 1 call 1 returned: %s\n", s);
80: result = 1;
81: }
82: setto (2);
83:
84: waitfor (1);
85: s = gettext ("cheese");
86: puts (s);
87: if (strcmp (s, "K\344se"))
88: {
89: fprintf (stderr, "thread 1 call 2 returned: %s\n", s);
90: result = 1;
91: }
92: setto (2);
93:
94: return NULL;
95: }
96:
97: void *
98: thread2_execution (void *arg)
99: {
100: char *s;
101:
102: waitfor (2);
103: uselocale (newlocale (LC_ALL_MASK, "de_DE.UTF-8", NULL));
104: setto (1);
105:
106:
107:
108: waitfor (2);
109: s = gettext ("cheese");
110: puts (s);
111: if (strcmp (s, "K\303\244se"))
112: {
113: fprintf (stderr, "thread 2 call 1 returned: %s\n", s);
114: result = 1;
115: }
116: setto (1);
117:
118: waitfor (2);
119: s = gettext ("cheese");
120: puts (s);
121: if (strcmp (s, "K\303\244se"))
122: {
123: fprintf (stderr, "thread 2 call 2 returned: %s\n", s);
124: result = 1;
125: }
126: setto (1);
127:
128: return NULL;
129: }
130:
131: int
132: main (void)
133: {
134: pthread_t thread1;
135: pthread_t thread2;
136:
137: unsetenv ("LANGUAGE");
138: unsetenv ("OUTPUT_CHARSET");
139: textdomain ("codeset");
140: bindtextdomain ("codeset", OBJPFX "domaindir");
141: result = 0;
142:
143: flipflop = 1;
144: if (pthread_mutex_init (&lock, NULL))
145: exit (2);
146: if (pthread_cond_init (&waitqueue, NULL))
147: exit (2);
148: if (pthread_create (&thread1, NULL, &thread1_execution, NULL))
149: exit (2);
150: if (pthread_create (&thread2, NULL, &thread2_execution, NULL))
151: exit (2);
152: if (pthread_join (thread2, NULL))
153: exit (3);
154:
155: return result;
156: }