pthread_exit

執行緒通過調用pthread_exit函式終止執行,就如同進程在結束時調用exit函式一樣。這個函式的作用是,終止調用它的執行緒並返回一個指向某個對象的指針

基本介紹

  • 中文名:pthread_exit
  • 外文名:pthread_exit
  • 作用:終止調用它的執行緒等
  • 執行方式:調用pthread_exit函式終止執行
  • 性質:函式
定義,參數,

定義

void pthread_exit(void* retval);
pthread_exit()

參數

#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
void *print_message_function( void *ptr )
{
char *message;
message = (char *) ptr;
printf("%s \t", message);
printf("PID: %ld \n", pthread_self());
pthread_exit ("thread all done"); // 重點看 pthread_exit() 的參數,是一個字串,這個參數的指針可以通過
// pthread_join( thread1, &pth_join_ret1);
}
main()
{
pthread_t thread1, thread2;
char *message1 = "Thread 1";
char *message2 = "Thread 2";
int iret1, iret2;
void *pth_join_ret1;//="thread1 has done!";
void *pth_join_ret2;//="thread2 has done!";
/* Create independant threads each of which will execute function */
//pthread_create return 0 if create a thread is ok!
iret1 = pthread_create( &thread1, NULL, print_message_function, (void*)"thread one_here");
iret2 = pthread_create( &thread2, NULL, print_message_function, (void*) message2);
pthread_join( thread1, &pth_join_ret1);
pthread_join( thread2, &pth_join_ret2);
//
//if(pth_join_ret1==NULL || pth_join_ret2==NULL)

相關詞條

熱門詞條

聯絡我們