Espacios de nombres
Variantes
Acciones

std::packaged_task

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.
(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.
(C++11)
(C++11)
(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.
(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.
(C++11)
(C++11)
(C++11)
(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.
(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.
(C++11)
(C++11)
packaged_task
(C++11)
(C++11)
(C++11)
 
std::packaged_task
Las funciones miembro
Original:
Member functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Conseguir el resultado
Original:
Getting the result
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Ejecución
Original:
Execution
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
 
Definido en la cabecera <future>
template< class > class packaged_task; //not defined
(1) (desde C++11)
template< class R, class Args... >
class packaged_task<R(Args...)>;
(2) (desde C++11)
La plantilla std::packaged_task clase envuelve cualquier blanco que se puede llamar (función, expresión lambda, la expresión se unen, o de otro objeto de función) de modo que se puede invocar de forma asincrónica, y su valor de retorno o excepción producida se almacena en el estado compartido, que se puede acceder a través de std::future objetos .
Original:
The class template std::packaged_task wraps any callable target (function, lambda expression, bind expression, or another function object) so that it can be invoked asynchronously, and its return value or exception thrown is stored in the shared state, which can be accessed through std::future objects.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Al igual que std::function, std::packaged_task es polimórfico, asignador consciente de contenedor: el destino almacenada exigible podrá asignarse en el montón o con un factor de imputación prevista .
Original:
Just like std::function, std::packaged_task is a polymorphic, allocator-aware container: the stored callable target may be allocated on heap or with a provided allocator.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Contenido

[editar] Las funciones miembro

construye el objeto de tarea
Original:
constructs the task object
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(función miembro público) [editar]
destructs el objeto de tarea
Original:
destructs the task object
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(función miembro público) [editar]
mueve el objeto de trabajo
Original:
moves the task object
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(función miembro público) [editar]
Comprueba si el objeto de la tarea tiene una función válida
Original:
checks if the task object has a valid function
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(función miembro público) [editar]
swaps dos objetos de tarea
Original:
swaps two task objects
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(función miembro público) [editar]
Conseguir el resultado
Original:
Getting the result
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
devuelve un std::future asociado con el resultado prometido
Original:
returns a std::future associated with the promised result
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(función miembro público) [editar]
Ejecución
Original:
Execution
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
ejecuta la función
Original:
executes the function
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(función miembro público) [editar]
ejecuta la función de asegurar que el resultado está lista sólo una vez se cierra el subproceso actuales
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.

(función miembro público) [editar]
restablece el estado de abandono de los resultados almacenados de ejecuciones anteriores
Original:
resets the state abandoning any stored results of previous executions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(función miembro público) [editar]

[editar] Terceros funciones

el algoritmo se especializa std::swap
Original:
specializes the std::swap algorithm
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(plantilla de función) [editar]

[editar] Clases de ayuda

se especializa el rasgo tipo std::uses_allocator
Original:
specializes the std::uses_allocator type trait
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(especialización de plantilla de clase) [editar]

[editar] Ejemplo

#include <iostream>
#include <future>
#include <thread>
 
int main()
{
    std::packaged_task<int()> task([](){return 7;}); // wrap the function
    std::future<int> result = task.get_future();  // get a future
    std::thread(std::move(task)).detach(); // launch on a thread
    std::cout << "Waiting...";
    result.wait();
    std::cout << "Done!\nResult is " << result.get() << '\n';
}

Salida:

Waiting...Done!
Result is 7

[editar] Ver también

(C++11)
espera a un valor que se establece de forma asincrónica
Original:
waits for a value that is set asynchronously
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(plantilla de clase) [editar]