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);
}
参考资料:
1· http://zh.wikipedia.org/wiki/Native_POSIX_Thread_Library
2· http://www.yolinux.com/TUTORIALS/LinuxTutorialPosixThreads.html#BASICS