2017-02-25 5 views
3

TRUE ==)を終了し、(t1.joinを(参加しているどのようにスレッドをチェックするサービスウィンドウC++で終了するスレッドのセットまたは他のイベントを待つためにどのように

void ServiceManagement::ServiceWorkerThread() 
{ 
    // Periodically check if the service is stopping. 

    //Create thread t1 
    std::thread t1(Execution); 

    while (!m_fStopping ||! "t1 has joined ?") 
    { 
     // Perform main service function here... 
     ::Sleep(1000); // Simulate some lengthy operations. 
    } 
    SetEvent(m_hFinishedEvent); 

} 

にスレッドを作成します。 )?

+0

あなたの人生を楽にし、['std :: future'](http://en.cppreference.com/w/cpp/thread/future) – WhiZTiM

+0

あなたのガイドをありがとう –

答えて

2

std::futureをそのようなタスクに使用します。メンバー関数名wait_forがあり、これを利用して目的の目標を達成することができます。

関連する問題