pthread 基础篇 创建线程
2013-05-19 17:58
363 查看
1· 创建线程
thread: 创建线程后返回的相乘ID
attr:创建线程的属性,若为NULL,则按默认属性创建
start_routine:线程回调函数,即线程执行时调用的函数
arg:指向回调函数时传入的参数
基本用法:
void *thread1_proc_function(void *arg)
{
printf("i am sub thread!\n");
return NULL;
}
void main(void)
{
int iret
= 0;
pthread_t thread1;
iret
= pthread_create(&thread1, NULL, thread1_proc_function, NULL);
if(0 != iret)
{
printf("create pthread error");
}
exit(0);
}
参考资料:
1· http://zh.wikipedia.org/wiki/Native_POSIX_Thread_Library
2· http://www.yolinux.com/TUTORIALS/LinuxTutorialPosixThreads.html#BASICS
3· http://learn.akae.cn/media/ch35s03.html
int pthread_create(pthread_t * thread, const pthread_attr_t * attr, void * (*start_routine)(void *), void *arg);
thread: 创建线程后返回的相乘ID
attr:创建线程的属性,若为NULL,则按默认属性创建
start_routine:线程回调函数,即线程执行时调用的函数
arg:指向回调函数时传入的参数
基本用法:
void *thread1_proc_function(void *arg)
{
printf("i am sub thread!\n");
return NULL;
}
void main(void)
{
int iret
= 0;
pthread_t thread1;
iret
= pthread_create(&thread1, NULL, thread1_proc_function, NULL);
if(0 != iret)
{
printf("create pthread error");
}
exit(0);
}
参考资料:
1· http://zh.wikipedia.org/wiki/Native_POSIX_Thread_Library
2· http://www.yolinux.com/TUTORIALS/LinuxTutorialPosixThreads.html#BASICS
3· http://learn.akae.cn/media/ch35s03.html
相关文章推荐
- 线程创建函数pthread_create
- Linux学习-线程的创建和终止-(出现错误-undefined reference to 'pthread_create')
- 线程创建pthread
- pthread_create线程创建的过程剖析
- 将创建线程的API-pthread_create封装成一个线程类
- pthread线程创建出现undefined reference to `pthread_create' collect2: error: ld returned 1 exit status
- 初识pthread(一)-线程管理之创建/结束线程
- C++ pthread_create 线程创建与传参(struct)
- POSIX多线程之创建线程pthread_create && 线程清理pthread_cleanup
- Linux中以PTHREAD_CREATE_DETACHED属性创建线程
- 对线程创建函数pthread_create的总结
- linux 线程创建函数pthread_create的几个传参方式
- 线程的创建pthread_create.c
- linux创建线程之pthread_create
- linux 线程创建 pthread_create函数 获取线程id
- 创建脱离线程 pthread_attr_setdetachstate
- 使用pthread_create创建大量线程时,创建线程失败,Resource temporarily unavailable的解决办法
- pthread_create()创建线程时传入多个參数
- pthread 基础篇 结束线程
- pthread_create函数创建线程失败的原因