Chinaunix首页 | 论坛 | 博客
  • 博客访问: 756771
  • 博文数量: 231
  • 博客积分: 3217
  • 博客等级: 中校
  • 技术积分: 2053
  • 用 户 组: 普通用户
  • 注册时间: 2011-07-04 12:01
文章分类

全部博文(231)

文章存档

2015年(1)

2013年(10)

2012年(92)

2011年(128)

分类: LINUX

2011-09-06 11:44:00

线程函数:
头文件:#include
 
比较两个线程ID函数:
int pthread_equal(pthread_t tid1, pthread_t tid2)
返回值:若相等则返回非零值,否则就返回0.
 
调用pthread_self函数获得自身的线程ID
pthread_t pthread_self(void);
返回值:调用线程的ID
 
pthread_create函数创建新线程
int pthread_create(pthread_t *restrict tidp ,const pthread_attr_t *restrict attr,void *(start_rtn)(void *),void *restrict arg);
返回值:若成功则返回0,否则返回错误编号。
当返回成功时tidp指向的内存单元被设置为新创建的线程的ID。attr参数用于定制各种不同的线程属性,默认为NULL,新创建的线程从start_rtn函数的地址开始运行,该函数只有一个无类型指针参数arg,如果需要向start_rtn函数传递的参数不知一个那么需要把这些参数放到一个结构中,然后把这个结构的地址作为arg参数传入。
 
void pthread_exit(void *rval_ptr);
int pthread_join(pthread_t thread,void **rval_ptr)
返回值:返回0表示成功,否则返回错误编号
rval_ptr 是一个无类型指针,与传给启动例程的单个参数类似,进程中的其他线程可以通过调用pthread_join函数访问到这个指针。thread指定了将要等待的线程ID。
 
阅读(748) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~