1. 入口函数:
主线程的入口函数一般可以认为是main函数;
一般线程的入口函数定义: void * thread_fun( void * arg);
2. 如何启动普通线程:
#include <pthread.h> |
int pthread_create(pthread_t *restrict_tidp, const pthread _attr_t *restrict_attr, void *(*start_rtn)(void), void *restrict_arg); |
1)成功返回0,否则返回错误号;
2)成功时:restrict_tidp是新线程id号;可以通过pthread_self()函数来得到此线程的id;
3)restrict_attr:新线程的属性,若为NULL,则默认属性;
4)start_rtn: 入口函数
5)restrict_arg: 入口函数的入参
3. 如何终止普通线程:
终止方式:
1)线程从启动例程中返回&#