pthread_exit
- 功能:退出线程
- 原型:
void pthread_exit(void *retval);
- 参数:
1)void* retval - 返回值:
无返回值 - DO
#include <func.h>
void print_ids(const char* prefix) {
printf("%s: ", prefix);
printf("pid = %d, ppid = %d, tid = %lu\n",
getpid(), getppid(), pthread_self());
}
void* start_routine(void* args) {
print_ids("new_thread");
pthread_exit(NULL);
printf("new_thread: Cannot see me!\n");
return NULL;
}
int main(int argc, char* argv[]) {
print_ids("main");
pthread_t tid;
int err = pthread_create(&tid, NULL, start_routine, NULL);
if (err) {
error(1, err, "pthread_create");
}
sleep(2);
return 0;
}