posix thread线程

1. pthread线程通过调用你提供的某些函数开始。这个“线程函数”应该只有一个void*型参数,并返回系统的类型。
2. 通过向pthread_create函数传递线程函数的地址和线程函数调用的参数来参加线程。
3. 线程可以通过pthread_self获取自己的ID。
4. 除非线程的创建者或者线程本身将线程ID存于某处,否则不可能获得一个线程的ID。
5. 分离线程意味着通知系统不再需要此线程,允许系统将分配给他的资源回收。
6. 线程阻塞条件:试图加锁一个已经被锁住的互斥量;等待某个条件变量;调用singwait等待尚未发生的信号;执行无法立即完成的IO操作。
7. 线程终止将释放所有系统资源,但是必须释放由该线程占有的程序资源。

 1 #include<pthread.h>
 2 #include "errors.h"
 3 
 4 void *thread_routine(void* arg)
 5 {
 6     return arg;
 7 }
 8 
 9 int
10 main(int argc, char* argv[])
11 {
12     pthread_t thread_id;
13     void* thread_result;
14     int status;
15 
16     status = pthread_create(&thread_id, NULL, thread_routine, NULL);
17     if( status != 0)
18         err_abort(status, "pthread_create");
19     status = pthread_join(thread_id, &thread_result);
20     if( status != 0)
21         err_abort(status, "pthread_join");
22     if( thread_result == NULL)
23         return 0;
24     else
25         return 1;
26 }
原文地址:https://www.cnblogs.com/licongyu/p/5044545.html