コード例 #1
0
int main()
{
  {
    int some_local_state;
    boost::strict_scoped_thread<> t( (boost::thread(func(some_local_state))));

    do_something_in_current_thread();
  }
  {
    int some_local_state;
    boost::thread t(( func(some_local_state) ));
    boost::strict_scoped_thread<> g( (boost::move(t)) );

    do_something_in_current_thread();
  }
//  {
//    int some_local_state;
//    boost::thread t(( func(some_local_state) ));
//    boost::strict_scoped_thread<> g( (boost::move(t)) );
//
//    do_something_in_current_thread();
//    do_something_with_current_thread(boost::thread(g));
//  }
  return 0;
}
コード例 #2
0
ファイル: listing_2.6.cpp プロジェクト: AnnYN/CCiA
void f()
{
    int some_local_state;
    scoped_thread t(std::thread(func(some_local_state)));
        
    do_something_in_current_thread();
}
コード例 #3
0
ファイル: exp2.cpp プロジェクト: ZMacer/CPP-Concurrency
 void f()
{
    int some_local_state = 0;
    func my_func(some_local_state);
    std::thread t(my_func);
    thread_guard g(t);//方法二:确保当前线程退出时,正确等待线程t完成
    do_something_in_current_thread();
}
コード例 #4
0
ファイル: scoped_thread.cpp プロジェクト: AlexMioMio/boost
int main()
{
  {
    int some_local_state;
    boost::strict_scoped_thread<> t( (boost::thread(func(some_local_state))));

    do_something_in_current_thread();
  }
  {
    int some_local_state;
    boost::thread t(( func(some_local_state) ));
    boost::strict_scoped_thread<> g( (boost::move(t)) );

    do_something_in_current_thread();
  }
//  {
//    int some_local_state;
//    boost::thread t(( func(some_local_state) ));
//    boost::strict_scoped_thread<> g( (boost::move(t)) );
//
//    do_something_in_current_thread();
//    do_something_with_current_thread(boost::thread(g));
//  }
  {
    int some_local_state;
    boost::scoped_thread<> t( (boost::thread(func(some_local_state))));

    if (t.joinable())
      t.join();
    else
      do_something_in_current_thread();
  }
  {
    int some_local_state;
    boost::thread t(( func(some_local_state) ));
    boost::scoped_thread<> g( (boost::move(t)) );
    t.detach();

    do_something_in_current_thread();
  }
  {
    boost::scoped_thread<> g( &f, 1, 2 );
    do_something_in_current_thread();
  }
  return 0;
}
コード例 #5
0
ファイル: listing_2.3.cpp プロジェクト: zzragida/CppExamples
void f()
{
	int some_local_state;
	func my_func(some_local_state);
	std::thread t(my_func);
	thread_guard g(t);

	do_something_in_current_thread();
}
コード例 #6
0
ファイル: listing_2.2.cpp プロジェクト: AnnYN/CCiA
void f()
{
    int some_local_state=0;
    func my_func(some_local_state);
    std::thread t(my_func);
    try
    {
        do_something_in_current_thread();
    }
    catch(...)
    {
        t.join();
        throw;
    }
    t.join();
}