1 /* Simple test code with no bug */
8 static void* thread1_fun(void* ignore)
10 pthread_mutex_lock(&mutex);
11 pthread_mutex_unlock(&mutex);
13 fprintf(stderr, "The first thread is terminating.\n");
16 static void* thread2_fun(void* ignore)
18 pthread_mutex_lock(&mutex);
19 pthread_mutex_unlock(&mutex);
21 fprintf(stderr, "The second thread is terminating.\n");
25 int main(int argc, char* argv[])
27 pthread_mutex_init(&mutex, NULL);
29 pthread_t thread1, thread2;
30 pthread_create(&thread1, NULL, thread1_fun, NULL);
31 pthread_create(&thread2, NULL, thread2_fun, NULL);
32 fprintf(stderr, "All threads are started.\n");
33 pthread_join(thread1, NULL);
34 pthread_join(thread2, NULL);
36 fprintf(stderr, "User's main is terminating.\n");