【发布时间】:2016-06-29 06:19:58
【问题描述】:
#include <pthread.h>
#include <stdio.h>
typedef struct thread_char_para {
char character;
int count;
} thread_char_para;
void* char_print (void* parameter)
{
thread_char_para* p = (thread_char_para*)parameter;
int i;
for (i = 0; i < p->count; ++i)
fputc(p->character, stderr);
return NULL;
}
int main()
{
pthread_t thread1;
pthread_t thread2;
thread_char_para para1 = {'x', 30000};
thread_char_para para2 = {'o', 30000};
pthread_create(&thread1, NULL, char_print, ¶1);
pthread_create(&thread2, NULL, char_print, ¶2);
return 0;
}
为什么没有任何输出?
我还找到了一些阅读链接:Detached vs. Joinable POSIX threads
在这个链接中,它说pthread_join 不是必需的。所以,我想知道。
【问题讨论】:
-
如果不使用
pthread_join,程序可能会在线程运行之前退出 -
查看您的历史记录,您也可以通过your previous question得到答案