posix-pthread (1)
2017-03-22 本文已影响12人
ColdRomantic
进程和线程api对比
进程 | 线程 |
---|---|
pid_t | thread_t |
fork | pthread_create |
waitpid | pthread_jion |
exit | pthread_exit |
在main函数中调用return | 在线程函数中调用return |
僵进程 | 僵线程 |
wait_pid | pthread_jion |
pthread_detach | |
kill | pthread_cancel |
知识点
1 使用pthread_detach 方法脱离一个线程就不会产生僵线程。
2 获取当前县城id

3 pthread_cancel可以杀死一个执行中的线程。
线程结束
自杀: pthread_exit ,在线程入口函数中调用return.
他杀: pthread_cancel