我正在学习如何使用<pthread.h>
,课本上说:
函数
pthread_join
会阻塞调用线程...
但在我的测试中,它没有:
void *a_thread(void *pt) {
puts("a_thread:join");
pthread_join(*(pthread_t *)pt, NULL); // <-- a_thread didn't wait for
puts("a_thread:joined"); // itself to finish executing.
return NULL;
}
int main(void) {
pthread_t t;
puts("create");
pthread_create(&t, NULL, a_thread, &t);
puts("created");
puts("main:join");
pthread_join(t, NULL);
puts("main:joined");
}
gcc -Og -o test test.c; ./test
:
create
created
main:join
a_thread:join
a_thread:joined
main:joined