當前位置:編程學習大全網 - 編程軟體 - 關於linux下多線程編程

關於linux下多線程編程

pthread_join 線程停止等待函數沒有調用

pthread_create 線程生成後,沒有等子線程停止,主線程就先停止了。

主線程停止後,整個程序停止,子線程在沒有printf的時候就被結束了。

結論:不是妳沒有看到結果,而是在子線程printf("..................\n");之前整個程序就已經停止了。

#include <stdio.h>

#include <stdlib.h>

#include <sys/types.h>

#include <string.h>

#include <unistd.h>

#include <pthread.h>

#define FALSE -1

#define TRUE 0

void *shuchu( void *dumy )

{

int j;

printf("..................\n");

}

int main()

{

int i = 0;

int rc = 0;

int ret1;

pthread_t p_thread1;

if(0!=(ret1 = pthread_create(&p_thread1, NULL, shuchu, NULL)))printf("sfdfsdfi\n");

printf("[%d]\n",p_thread1);

pthread_join(p_thread1, NULL);

return TRUE;

}

  • 上一篇:人才的含義是什麽?
  • 下一篇:在steam裏買了gmod,就可以玩躲貓貓了嗎?
  • copyright 2024編程學習大全網