__proc_give_cores correctly adjusts amt_granted
[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_safe("About to create thread 1\n");
28         pthread_create(&t1, NULL, &thread, NULL);
29         printf_safe("About to create thread 2\n");
30         pthread_create(&t2, NULL, &thread, NULL);
31
32         printf_safe("About to join on thread 0\n");
33         pthread_join(t0, NULL);
34         printf_safe("About to join on thread 1\n");
35         pthread_join(t1, NULL);
36         printf_safe("About to join on thread 2\n");
37         pthread_join(t2, NULL);
38