2012年2月8日 星期三

pthread_create ()

1 pthread_create(&Thread_ID , attribute, Void * function (void *) , &value )

創造一個 pthread 一定需要的函式
第一個是 pthread 的名字
第二個是 pthread 的特徵 => 待續
第三個是 pthread 要做的 function 注意 這個 function 一定要是 接收 void * 變數 和 回傳 void * 的變數
第四個 是 這個 function 所需要的 參數


example



#include
#include
#include
#include


void *funct(void *arg )
{
printf( " hello this is thread");

}

int main()
{

pthread_t thread_a;
pthread_create(&thread_a, NULL, funct, NULL );
pthread_join (thread_a,NULL); //等待 thread 被執行完畢

printf("the sub-thread has done");
return 0;

}

沒有留言:

張貼留言