pthread后main不会继续

tca*_*cak 4 c++ multithreading gcc pthreads codeblocks

我使用Ubuntu 10.10,Code :: Blocks with GCC 4.2.

我写了这样的代码:

#include <iostream>
#include <stdlib.h>
#include <pthread.h>

using namespace std;

void *thread1proc(void* param){
    while(true)
    cout << "1";

    return 0;
}

int main(){
    pthread_t thread1;

    pthread_create(&thread1,NULL,thread1proc,NULL);
    pthread_join(thread1,NULL);

    cout << "hello";
}
Run Code Online (Sandbox Code Playgroud)

主要开始,创建线程.但奇怪(对我来说)主要是不继续运行.我希望在屏幕和程序结束时看到"hello"消息.因为在Windows中,在Delphi中它对我有用.如果"main"也是一个线程,为什么它不继续运行?是关于POSIX线程吗?

谢谢.

Ree*_*ore 7

pthread_join将阻塞直到thread1完成(调用pthread_exit或返回),它(因为它有一个无限循环)它永远不会.