std::notify_all_at_thread_exit
Da cppreference.com.
![]() |
Questa pagina è stata tradotta in modo automatico dalla versione in ineglese della wiki usando Google Translate.
La traduzione potrebbe contenere errori e termini strani. Muovi il puntatore sopra al testo per vedere la versione originale. Puoi aiutarci a correggere gli gli errori. Per ulteriori istruzioni clicca qui. |
Elemento definito nell'header <condition_variable>
|
||
void notify_all_at_thread_exit( std::condition_variable& cond, std::unique_lock<std::mutex> lk ); |
(dal C++11) | |
notify_all_at_thread_exit
fornisce un meccanismo per avvisare gli altri thread che un determinato thread è completamente finito, compreso distruggere tutti gli oggetti thread_local. Si opera come segue: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.
You can help to correct and verify the translation. Click here for instructions.
- La proprietà del
lk
blocco precedentemente acquisito viene trasferito nella memoria interna.Original:Ownership of the previously acquired locklk
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.
- L'ambiente di esecuzione viene modificato in modo tale che quando il thread corrente, dopo i distruttori per tutti gli oggetti con filo durata di archiviazione locale sono chiamati, il
cond
variabile condizione è notificata come se da:Original:The execution environment is modified such that when the current thread exits, after the destructors for all objects with filo durata di archiviazione locale are called, the condition variablecond
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();
Un effetto equivalente può essere ottenuto con le funzioni fornite dai std::promise o 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.
You can help to correct and verify the translation. Click here for instructions.
Indice |
[modifica] Note
Chiamare questa funzione se
lock.mutex()
non è bloccato dal thread corrente è un comportamento indefinito.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.
You can help to correct and verify the translation. Click here for instructions.
Chiamare questa funzione se
lock.mutex()
non è lo stesso mutex come quello utilizzato da tutti gli altri thread che sono attualmente in attesa sulla variabile stessa condizione è un comportamento indefinito.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.
You can help to correct and verify the translation. Click here for instructions.
Il
lk
blocco in dotazione è mantenuto fino alla chiusura del thread. Una volta che questa funzione è stata richiamata, discussioni più può acquistare lo stesso blocco, al fine di aspettare cond
. Se qualche thread è in attesa su questa variabile di condizione, non dovrebbe tentare di liberare e riacquisire il blocco quando si sveglia spurio.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.
You can help to correct and verify the translation. Click here for instructions.
Nei casi tipici di utilizzo, questa funzione è l'ultima cosa detta da un thread indipendente.
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.
You can help to correct and verify the translation. Click here for instructions.
[modifica] Parametri
cond | - | la variabile di condizione di notificare all'uscita thread
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 | - | la serratura associata al
cond variabile di condizione 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. |
[modifica] Valore di ritorno
(Nessuno)
Original:
(none)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[modifica] Esempio
Questo frammento di codice illustra come
notify_all_at_thread_exit
parziale può essere utilizzato per evitare di accedere a dati che dipendono da gente del posto, mentre quei locali filo filo sono in procinto di essere distrutta:
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.
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 }
[modifica] Vedi anche
imposta il risultato al valore specifico offrendo allo stesso tempo la notifica solo dal thread 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. (metodo pubblico) | |
esegue la funzione di garantire che il risultato è solo una volta pronto il thread corrente 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. (metodo pubblico) |