Made ros_pop_tf work on SPARC
[akaros.git] / tests / pthread_test.c
1 #include <rstdio.h>
2 #include <pthread.h>
3
4 pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
5 #define printf_safe(...) \
6         pthread_mutex_lock(&lock); \
7         printf(__VA_ARGS__); \
8         pthread_mutex_unlock(&lock);
9
10 int thread_num;
11 pthread_t t0;
12 pthread_t t1;
13 pthread_t t2;
14
15 __thread int my_id;
16 void *thread(void* arg)
17 {       
18         my_id = thread_num++;
19         printf_safe("thread %d\n", my_id);
20 }
21
22 int main(int argc, char** argv) 
23 {
24         thread_num = 0;
25         printf_safe("About to create thread 0\n");
26         pthread_create(&t0, NULL, &thread, NULL);
27         printf("returned from creating him, spinning\n");
28         while(1);
29
30 //      printf_safe("About to create thread 1\n");
31 //      pthread_create(&t1, NULL, &thread, NULL);
32 //      printf_safe("About to create thread 2\n");
33 //      pthread_create(&t2, NULL, &thread, NULL);
34
35         printf_safe("About to join on thread 0\n");
36         pthread_join(t0, NULL);
37 //      printf_safe("About to join on thread 1\n");
38 //      pthread_join(t1, NULL);
39 //      printf_safe("About to join on thread 2\n");
40 //      pthread_join(t2, NULL);
41