pthread_create()函数
2017-07-29 21:52
369 查看
(1) 函数原型:
int pthread_create (pthread_t *thread_tid , const pthread_attr_t *attr , void * ( * start_routine )( void * ), void *arg );
(2) 头文件:
#include <pthread.h>
(3) 函数功能:
创建一个新的线程
(4) 参数说明:
thread_tid:如果新线程创建成功,参数[b]thread_tid
返回新生成的线程的id,一个进程中的每个线程都有一个线程ID,其类型为[b]thread_tid;[/b][/b]
attr:指向线程属性的指针,每个线程都有很多属性,包括优先级,起始栈大小,是否是守护线程等,通常将[b]attr参数的值设置为NULL,这是使用系统默认的属性。[/b]
[b]start_routine
:处理线程函数的地址,该函数必须是一个静态的函数,该函数参数是一个通用指针arg;
[/b]
arg:
[b]start_routine ()中的参数,如果想传递多个参数的话,需要将多个参数打包成结构体,然后将arg指向该结构体。[/b]
(5) 返回值:
成功:0
失败:非零
(6) [b]编译和链接时引用-lpthread[/b]
(7) 用法:
#include <pthread.h>
pthread_t tid;
int arg;
void *function(void *arg);
if( pthread_create( &tid, NULL, function, (void*)&arg) )
{
//处理异常
exit(1);
}
int pthread_create (pthread_t *thread_tid , const pthread_attr_t *attr , void * ( * start_routine )( void * ), void *arg );
(2) 头文件:
#include <pthread.h>
(3) 函数功能:
创建一个新的线程
(4) 参数说明:
thread_tid:如果新线程创建成功,参数[b]thread_tid
返回新生成的线程的id,一个进程中的每个线程都有一个线程ID,其类型为[b]thread_tid;[/b][/b]
attr:指向线程属性的指针,每个线程都有很多属性,包括优先级,起始栈大小,是否是守护线程等,通常将[b]attr参数的值设置为NULL,这是使用系统默认的属性。[/b]
[b]start_routine
:处理线程函数的地址,该函数必须是一个静态的函数,该函数参数是一个通用指针arg;
[/b]
arg:
[b]start_routine ()中的参数,如果想传递多个参数的话,需要将多个参数打包成结构体,然后将arg指向该结构体。[/b]
(5) 返回值:
成功:0
失败:非零
(6) [b]编译和链接时引用-lpthread[/b]
(7) 用法:
#include <pthread.h>
pthread_t tid;
int arg;
void *function(void *arg);
if( pthread_create( &tid, NULL, function, (void*)&arg) )
{
//处理异常
exit(1);
}
相关文章推荐
- 为什么在C++使用pthread_create()的时候,类成员函数做线程的处理函数必须要定义成static类型的?
- 在C++的类中,普通成员函数不能作为pthread_create的线程函数,如果要作为pthread_create中的线程函数,必须是static
- TSD中的几个函数,pthread_key_create pthread_getspecific
- pthread库中操作线程专有数据的函数:pthread_key_create,pthread_setspecific,pthread_gtespecific,pthread_key_delete
- C++中使用pthread.h头文件报错 - 无法解析的外部符号 __imp__pthread_create,该符号在函数 _main 中被引用
- eclipse 函数编译时报错:undefined reference to `pthread_create’
- eclipse 函数编译时报错:undefined reference to `pthread_create’
- pthread_create函数编译时报错:undefined reference to 'pthread_create'
- 类成员函数作为pthread_create函数参数
- [转]pthread_create函数编译时报错:undefined reference to 'pthread_c...
- pthread_create 函数引发的几点思考
- 基于pthread_create,readlink,getpid等函数的学习与总结
- 线程的创建pthread_create()函数(线程一)
- linux下Qt调用非标准库中的函数调用----------如pthread_create、pthread_cond_***、、
- codeblocks 多线程 pthread_create 函数未定义引用 解决办法
- pthread_create使用类中函数指针的…
- pthread_create函数编译时报错:undefined reference to 'pthread_create'
- linux 线程创建函数pthread_create的几个传参方式
- TSD相关的 4 个函数: pthread_key_create(); pthread_key_delete(); pthread_getspecific(); pthread_sets
- pthread_create使用类中函数指针的…