c下的线程
来源:互联网 发布:域名快速备案阿里云 编辑:程序博客网 时间:2024/04/28 07:45
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调用一样用来等待指定的线程.
eg:
#include <pthread.h>
#include <stdio.h>
/* Prints x’s to stderr. The parameter is unused. Does not return. */
void* print_xs (void* unused)
{
while (1)
fputc (‘x’, stderr);
return NULL;
}
/* The main program. */
int main ()
{
pthread_t thread_id;
/* Create a new thread. The new thread will run the print_xs
function. */
pthread_create (&thread_id, NULL, &print_xs, NULL);
/* Print o’s continuously to stderr. */
while (1)
fputc (‘o’, stderr);
return 0;
}
- c下的线程
- Linux下C线程池的实现
- Linux下C线程池的实现
- Linux下C线程池的实现
- linux下C语言线程的介绍
- Linux下C线程池的实现
- Linux下的C语言线程池
- linux下c的线程池
- inux 下的c线程管理
- Linux下C线程池的实现
- Linux下C线程池的实现
- Linux下C线程池的实现
- linux下c线程
- Window下C线程
- {linux C}之linux下的C线程池
- linux下的c线程(写的非常好)
- linux下C实现线程池的源代码
- Linux下通用线程池的创建与使用(C++)
- o'reily ip routing memo part03
- 求两文本最大匹配窜
- Ajax 简介
- SQL注入式攻击代码分析
- 安全的PHP代码写数据库Mysql写法
- c下的线程
- Struts国际化资源文件中文转码
- Hello World !
- 研究一下springside的核心部分源代码
- Flex 包容Ajax 超越Ajax
- 网络用语
- 合并DataGrid相同的行
- 测试以下
- 鼠标拖曳实现svg矩形的任意切分