Ubuntu 10.10、Code :: Blocks withGCC4.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";
}
メインが起動し、スレッドを作成します。しかし、(私にとって)奇妙なのは、メインが実行を継続しないことです。画面とプログラムの最後に「こんにちは」というメッセージが表示されることを期待しています。Windowsでは、Delphiではそのように機能したからです。「メイン」もスレッドの場合、なぜ実行を継続しないのですか?POSIXスレッドについてですか?
ありがとうございました。