p_tan's blog

勉強日記です。ツッコミ大歓迎

boost::thread::timed_join

  • thread::timed_join : joinの時間指定版
  • 指定時間待ってもスレッドが終わらなければfalseを返す。
#include <boost/thread.hpp>

void worker()
{
	printf("worker start.\n");
	int c = 0;
	for(int i = 0; i < (1 << 30); i++){
		c++;
	}
	printf("worker end.\n");
}

int main()
{
	boost::thread t(&worker);
	while(!t.timed_join(boost::posix_time::seconds(1))){
		printf("マダァ?(・∀・ )っ/凵⌒☆チンチン\n");
	}
	return 0;
}

出力例(デバッグ実行)

worker start.
マダァ?(・∀・ )っ/凵⌒☆チンチン
マダァ?(・∀・ )っ/凵⌒☆チンチン
マダァ?(・∀・ )っ/凵⌒☆チンチン
worker end.