std::call_once
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 <mutex> | ||
template<class Function, class... Args> void call_once(std::once_flag& flag, Function&& f, Args&& args... ); | (dal C++11) | |
Esegue la funzione
f
esattamente una volta, anche se chiamato da più thread. Original:
Executes the function
f
exactly once, even if called from several threads. 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.
Ogni gruppo di invocazioni
call_once
che riceve lo stesso oggetto std::once_flag soddisferà i seguenti requisiti:Original:
Each group of
call_once
invocations that receives the same std::once_flag object will meet the following requirements: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.
- Esattamente una esecuzione di esattamente una delle funzioni (passato come
f
alle invocazioni del gruppo) viene eseguita. Esso è definito quale funzione verrà selezionato per l'esecuzione. La funzione selezionata viene eseguito nello stesso thread come invocazionecall_once
è stato passato a.Original:Exactly one execution of exactly one of the functions (passed asf
to the invocations in the group) is performed. It is undefined which function will be selected for execution. The selected function runs in the same thread as thecall_once
invocation it was passed to.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
- No invocazione nei rendimenti gruppo prima dell'esecuzione della suddetta funzione selezionata viene completato correttamente, cioè non esce con un'eccezione.Original:No invocation in the group returns before the abovementioned execution of the selected function is completed successfully, that is, doesn't exit via an exception.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
- Se le uscite funzione selezionate attraverso eccezione, si propaga al chiamante. Un'altra funzione è quindi selezionato ed eseguito.Original:If the selected function exits via exception, it is propagated to the caller. Another function is then selected and executed.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Indice |
[modifica]Parametri
flag | - | un oggetto, per cui esattamente una funzione viene eseguita Original: an object, for which exactly one function gets executed The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
f | - | funzione da chiamare Original: function to call The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
args... | - | argomenti da passare alla funzione Original: arguments to pass to the function 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]Eccezioni
- std::system_error eventuale condizione impedisce le chiamate a
call_once
dall'esecuzione come specificatoOriginal:std::system_error if any condition prevents calls tocall_once
from executing as specifiedThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - qualsiasi eccezione generata dal
f
Original:any exception thrown byf
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
[modifica]Esempio
#include <iostream>#include <thread>#include <mutex> std::once_flag flag; void do_once(){ std::call_once(flag, [](){std::cout<<"Called once"<<std::endl;});} int main(){std::thread t1(do_once);std::thread t2(do_once);std::thread t3(do_once);std::thread t4(do_once); t1.join(); t2.join(); t3.join(); t4.join();}
Output:
Called once
[modifica]Vedi anche
(C++11) | oggetto di supporto per garantire che call_once richiama la funzione una sola volta Original: helper object to ensure that call_once invokes the function only once The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (classe) |