I am learning how to use <pthread.h>
, and the textbook says that:
The
pthread_join
function blocks the calling thread ...
But in my test, it didn't:
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