您的位置:首页 > 其它

pthread 基础篇 创建线程

2013-05-19 17:58 363 查看
1· 创建线程

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);

}

参考资料:

http://zh.wikipedia.org/wiki/Native_POSIX_Thread_Library

http://www.yolinux.com/TUTORIALS/LinuxTutorialPosixThreads.html#BASICS

http://learn.akae.cn/media/ch35s03.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: