Mercurial > hg > octave-shane > gnulib-hg
comparison tests/test-tls.c @ 12421:e8d2c6fc33ad
Use spaces for indentation, not tabs.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Thu, 10 Dec 2009 20:28:30 +0100 |
parents | fbae6908522f |
children | b5e42ef33b49 |
comparison
equal
deleted
inserted
replaced
12420:5850b9a81029 | 12421:e8d2c6fc33ad |
---|---|
95 for (i = 0; i < KEYS_COUNT; i++) | 95 for (i = 0; i < KEYS_COUNT; i++) |
96 { | 96 { |
97 values[i] = (((unsigned int) rand() >> 3) % 1000000) * THREAD_COUNT + id; | 97 values[i] = (((unsigned int) rand() >> 3) % 1000000) * THREAD_COUNT + id; |
98 /* Hopefully no arithmetic overflow. */ | 98 /* Hopefully no arithmetic overflow. */ |
99 if ((values[i] % THREAD_COUNT) != id) | 99 if ((values[i] % THREAD_COUNT) != id) |
100 abort (); | 100 abort (); |
101 } | 101 } |
102 perhaps_yield (); | 102 perhaps_yield (); |
103 | 103 |
104 /* Verify that the initial value is NULL. */ | 104 /* Verify that the initial value is NULL. */ |
105 dbgprintf ("Worker %p before initial verify\n", gl_thread_self ()); | 105 dbgprintf ("Worker %p before initial verify\n", gl_thread_self ()); |
125 { | 125 { |
126 dbgprintf ("Worker %p doing value swapping\n", gl_thread_self ()); | 126 dbgprintf ("Worker %p doing value swapping\n", gl_thread_self ()); |
127 i = ((unsigned int) rand() >> 3) % KEYS_COUNT; | 127 i = ((unsigned int) rand() >> 3) % KEYS_COUNT; |
128 j = ((unsigned int) rand() >> 3) % KEYS_COUNT; | 128 j = ((unsigned int) rand() >> 3) % KEYS_COUNT; |
129 if (i != j) | 129 if (i != j) |
130 { | 130 { |
131 void *vi = gl_tls_get (mykeys[i]); | 131 void *vi = gl_tls_get (mykeys[i]); |
132 void *vj = gl_tls_get (mykeys[j]); | 132 void *vj = gl_tls_get (mykeys[j]); |
133 | 133 |
134 gl_tls_set (mykeys[i], vj); | 134 gl_tls_set (mykeys[i], vj); |
135 gl_tls_set (mykeys[j], vi); | 135 gl_tls_set (mykeys[j], vi); |
136 } | 136 } |
137 perhaps_yield (); | 137 perhaps_yield (); |
138 } | 138 } |
139 | 139 |
140 /* Verify that all the values are from this thread. */ | 140 /* Verify that all the values are from this thread. */ |
141 dbgprintf ("Worker %p before final verify\n", gl_thread_self ()); | 141 dbgprintf ("Worker %p before final verify\n", gl_thread_self ()); |
157 for (pass = 0; pass < 2; pass++) | 157 for (pass = 0; pass < 2; pass++) |
158 { | 158 { |
159 gl_thread_t threads[THREAD_COUNT]; | 159 gl_thread_t threads[THREAD_COUNT]; |
160 | 160 |
161 if (pass == 0) | 161 if (pass == 0) |
162 for (i = 0; i < KEYS_COUNT; i++) | 162 for (i = 0; i < KEYS_COUNT; i++) |
163 gl_tls_key_init (mykeys[i], free); | 163 gl_tls_key_init (mykeys[i], free); |
164 else | 164 else |
165 for (i = KEYS_COUNT - 1; i >= 0; i--) | 165 for (i = KEYS_COUNT - 1; i >= 0; i--) |
166 gl_tls_key_init (mykeys[i], free); | 166 gl_tls_key_init (mykeys[i], free); |
167 | 167 |
168 /* Spawn the threads. */ | 168 /* Spawn the threads. */ |
169 for (i = 0; i < THREAD_COUNT; i++) | 169 for (i = 0; i < THREAD_COUNT; i++) |
170 threads[i] = gl_thread_create (worker_thread, NULL); | 170 threads[i] = gl_thread_create (worker_thread, NULL); |
171 | 171 |
172 /* Wait for the threads to terminate. */ | 172 /* Wait for the threads to terminate. */ |
173 for (i = 0; i < THREAD_COUNT; i++) | 173 for (i = 0; i < THREAD_COUNT; i++) |
174 gl_thread_join (threads[i], NULL); | 174 gl_thread_join (threads[i], NULL); |
175 | 175 |
176 for (i = 0; i < KEYS_COUNT; i++) | 176 for (i = 0; i < KEYS_COUNT; i++) |
177 gl_tls_key_destroy (mykeys[i]); | 177 gl_tls_key_destroy (mykeys[i]); |
178 } | 178 } |
179 } | 179 } |
180 | 180 |
181 | 181 |
182 /* -------------------------------------------------------------------------- */ | 182 /* -------------------------------------------------------------------------- */ |