名前空間
変種
操作

std::notify_all_at_thread_exit

提供: cppreference.com
< cpp‎ | thread

 
 
スレッドのサポートライブラリ
スレッド
Original:
Threads
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
thread(C++11)
this_thread空間
Original:
this_thread namespace
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
get_id(C++11)
yield(C++11)
sleep_for(C++11)
sleep_until(C++11)
相互排除
Original:
Mutual exclusion
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
mutex(C++11)
timed_mutex(C++11)
汎用のロック管理
Original:
Generic lock management
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
lock_guard(C++11)
unique_lock(C++11)
defer_lock_t
try_to_lock_t
adopt_lock_t
(C++11)
(C++11)
(C++11)
lock(C++11)
try_lock(C++11)
defer_lock
try_to_lock
adopt_lock
(C++11)
(C++11)
(C++11)
条件変数
Original:
Condition variables
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
condition_variable(C++11)
condition_variable_any(C++11)
notify_all_at_thread_exit(C++11)
cv_status(C++11)
先物
Original:
Futures
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
promise(C++11)
future(C++11)
shared_future(C++11)
packaged_task(C++11)
async(C++11)
launch(C++11)
future_status(C++11)
future_error(C++11)
future_category(C++11)
future_errc(C++11)
 
Defined in header <condition_variable>
void notify_all_at_thread_exit( std::condition_variable& cond,
                                std::unique_lock<std::mutex> lk );
(C + + 11以来)
notify_all_at_thread_exitすべてthread_localオブジェクトの破棄を含む、指定されたスレッドが完全に終了したことを他のスレッドに通知するメカニズムを提供します。それは次のように動作します
Original:
notify_all_at_thread_exit provides a mechanism to notify other threads that a given thread has completely finished, including destroying all thread_local objects. It operates as follows:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
  • 以前に取得したロックlkの所有権は、内部ストレージに転送されます.
    Original:
    Ownership of the previously acquired lock lk is transferred to internal storage.
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • 実行環境は、現在のスレッドが終了すると、スレッドローカル記憶域期間を持つすべてのオブジェクトのデストラクタの後に呼び出されたときに、条件変数condがでているかのように通知されるように変更されます
    Original:
    The execution environment is modified such that when the current thread exits, after the destructors for all objects with スレッドローカル記憶域期間 are called, the condition variable cond is notified as if by:
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.

lk.unlock();
cond.notify_all();

同等の効果がstd::promiseまたはstd::packaged_taskによって提供される機能を達成することができる.
Original:
An equivalent effect may be achieved with the facilities provided by std::promise or std::packaged_task.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

目次

[編集] ノート

lock.mutex()が現在のスレッドによってロックされていない場合は、この関数を呼び出すと、未定義の動作です.
Original:
Calling this function if lock.mutex() is not locked by the current thread is undefined behavior.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
lock.mutex()は現在同じ条件変数で待っている他のすべてのスレッドが使用するものと同じミューテックスない場合は、この関数を呼び出すと、未定義の動作です.
Original:
Calling this function if lock.mutex() is not the same mutex as the one used by all other threads that are currently waiting on the same condition variable is undefined behavior.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
付属のロックlkは、スレッドが終了するまで保持されます。この関数が呼び出された後、これ以上スレッドはcondで待機するためには、同じロックを取得することができる。いくつかのスレッドがこの条件変数で待っている場合、それは偽って目覚める時にはロックを解放し、再取得を試みるべきではありません.
Original:
The supplied lock lk is held until the thread exits. Once this function has been called, no more threads may acquire the same lock in order to wait on cond. If some thread is waiting on this condition variable, it should not attempt to release and reacquire the lock when it wakes up spuriously.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
典型的な使用例では、この関数は、デタッチされたスレッドによって呼び出される最後のものです.
Original:
In typical use cases, this function is the last thing called by a detached thread.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集] パラメータ

cond -
条件変数は、スレッドの終了時に通知する
Original:
the condition variable to notify at thread exit
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
lk -
ロックは、条件変数condに関連付けられている
Original:
the lock associated with the condition variable cond
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集] 値を返します

(なし)
Original:
(none)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集]

この部分のコードは、notify_all_at_thread_exitがそれらのスレッドの地元の人々が破壊されている途中でスレッド住民に依存するデータへのアクセスを回避するために使用することができる方法を示しています
Original:
This partial code fragment illustrates how notify_all_at_thread_exit can be used to avoid accessing data that depends on thread locals while those thread locals are in the process of being destructed:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

#include <mutex>
#include <thread>
 
std::mutex m;
std::condition_variable cv;
 
bool ready = false;
ComplexType result;  // some arbitrary type
 
void thread_func()
{
    std::unique_lock<std::mutex> lk(m);
    // assign a value to result using thread_local data
    result = function_that_uses_thread_locals();
    ready = true;
    std::notify_all_at_thread_exit(cv, std::move(lk));
} // 1. destroy thread_locals, 2. unlock mutex, 3. notify cv
 
int main()
{
    std::thread t(thread_func);
    t.detach();
 
    // do other work
    // ...
 
    // wait for the detached thread
    std::unique_lock<std::mutex> lk(m);
    while(!ready) {
        cv.wait(lk);
    }
    process(result); // result is ready and thread_local destructors have finished
}


[編集] も参照してください

唯一のスレッドの終了時に通知を提供しながら、特定の値に結果を設定します
Original:
sets the result to specific value while delivering the notification only at thread exit
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(パブリックメンバ関数of std::promise) [edit]
結果は一度だけ現在のスレッドが終了する準備ができていることを確保する関数を実行します
Original:
executes the function ensuring that the result is ready only once the current thread exits
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(パブリックメンバ関数of std::packaged_task) [edit]