Espacios de nombres
Variantes
Acciones

std::call_once

De cppreference.com
< cpp‎ | thread

 
 
Tema Biblioteca de ayuda
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 espacio de nombres
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)
Exclusión mutua
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)
Gestión de bloqueos genérico
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)
Las variables de condición
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)
Futuros
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 <mutex>
template< class Function, class... Args >
void call_once( std::once_flag& flag, Function&& f, Args&& args... );
(desde C++11)
Ejecuta la función f exactamente una vez, incluso si se llama desde varios hilos .
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.
Cada grupo de invocaciones call_once que recibe el objeto std::once_flag mismo cumplirá con los siguientes requisitos:
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.
  • Exactamente una ejecución de exactamente una de las funciones (pasado como f a las invocaciones en el grupo) se lleva a cabo. No está definido cuál función será seleccionado para su ejecución. La función seleccionada se ejecuta en el mismo subproceso que la invocación call_once se pasó 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 invocación en el grupo vuelve antes de la ejecución antes mencionado de la función seleccionada se completa con éxito, es decir, no sale a través de una excepción .
    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.
  • Si las salidas de función seleccionada, en excepción, se propaga a la persona que llama. Otra función es entonces seleccionado y ejecutado .
    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.

Contenido

[editar] Parámetros

flag -
un objeto, para el que exactamente una función es ejecutada
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 -
funcionar a llamar
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... -
argumentos para pasar a la función
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.

[editar] Valor de retorno

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

[editar] Excepciones

  • std::system_error si cualquier condición impide que las llamadas a call_once se ejecute según lo especificado
    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.
  • cualquier excepción lanzada por 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.

[editar] Ejemplo

#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

[editar] Ver también

(C++11)
objeto de ayuda para asegurarse de que call_once invoca la función de una sola vez
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.

(clase) [edit]