std::call_once

Da cppreference.com.
< cpp‎ | thread

 
 
Discussione libreria di supporto
Threads
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 spazio dei nomi
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)
Mutua esclusione
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)
Blocco di gestione generico
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(C++11)
try_lock(C++11)
defer_lock
try_to_lock
adopt_lock
(C++11)
(C++11)
(C++11)
Condizioni variabili
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)
Futures
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)
 
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.
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.
  • 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 invocazione call_once è stato passato a.
    Original:
    Exactly one execution of exactly one of the functions (passed as f 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 the call_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.

[modifica]Eccezioni

  • std::system_error eventuale condizione impedisce le chiamate a call_once dall'esecuzione come specificato
    Original:
    std::system_error if any condition prevents calls to call_once from executing as specified
    The 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 by f
    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)[modifica]
close