| 1 |
#include <pthread.h> |
| 2 |
#include <stdio.h> |
| 3 |
#include <stdlib.h> |
| 4 |
#include <alloca.h> |
| 5 |
|
| 6 |
#if defined EXTERN_TLS |
| 7 |
__thread unsigned long tls = 99; |
| 8 |
#else |
| 9 |
static __thread unsigned long tls = 99; |
| 10 |
#endif |
| 11 |
|
| 12 |
void *increase_tls(void *arg); |
| 13 |
|
| 14 |
|
| 15 |
int main() |
| 16 |
{ |
| 17 |
pthread_t *thread; |
| 18 |
pthread_barrier_t barrier; |
| 19 |
int thread_count = 2; |
| 20 |
int i; |
| 21 |
|
| 22 |
pthread_barrier_init (&barrier, NULL, thread_count); |
| 23 |
char thread_name[] = |
| 24 |
{ '0', '1', '2', '3', '4', '5' }; |
| 25 |
|
| 26 |
thread = alloca (sizeof (pthread_t) * (thread_count + 1)); |
| 27 |
for (i = 1; i <= thread_count; i++) |
| 28 |
pthread_create (&thread[i], NULL, & increase_tls, &thread_name[i]); |
| 29 |
|
| 30 |
for (i = 1; i <= thread_count; i++) |
| 31 |
pthread_join (thread[i], NULL); |
| 32 |
} |