【Linux-C】线程

#include <pthread.h>

int pthread_create(

         pthread_t *thread,

         pthread_attr_t *attr,

         void *(*start_routine)(void *),

        void *arg

);

 

 

void pthread_exit(void *retval);

 

int pthread_join(pthread *thread,void **thread_return);

 

pthread_create创建一个线程,

     thread是用来表明创建线程的ID,

     attr指出线程创建时候的属性,我们用 NULL来表明使用缺省属性.

     start_routine函数指针是线程创建成功后开始执行的函数,

     arg是这个函数的唯一一个参数.表明传递给 start_routine的参数. 

 

pthread_exit函数和exit函数类似用来退出线程.这个函数结束线程,释放函数的资源,并在最后阻塞, 直到其他线程使用pthread_join函数等待它.然后将*retval的值传递给**thread_return.

 

由于这个函数释放所以的函数资源,所以retval不能够指向函数的局部变量. 

 

pthread_join和wait调用一样用来等待指定的线程. 

 

pthread_exit在start_routine退出的时候调用;

pthread_join在线程外面调用,接收线程的返回内容

 

例子见:http://www.jfox.info/c/a/id/18081h.html

 

 

你可能感兴趣的:(c,Linxu)