1 /* Simple test code with no bug */
8 static void* thread_fun(void* val)
10 pthread_mutex_lock(&mutex);
11 pthread_mutex_unlock(&mutex);
13 fprintf(stderr, "The thread %d is terminating.\n", *(int*)val);
17 int main(int argc, char* argv[])
19 pthread_mutex_init(&mutex, NULL);
24 pthread_create(&thread1, NULL, thread_fun, &id[0]);
25 pthread_create(&thread2, NULL, thread_fun, &id[1]);
26 fprintf(stderr, "All threads are started.\n");
27 pthread_join(thread1, NULL);
28 pthread_join(thread2, NULL);
30 pthread_mutex_destroy(&mutex);
32 fprintf(stderr, "User's main is terminating.\n");