std::thread::thread
De cppreference.com
|
|
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
| thread(); |
(1) | (depuis C++11) |
| thread( thread&& other ); |
(2) | (depuis C++11) |
| template< class Function, class... Args > explicit thread( Function&& f, Args&&... args ); |
(3) | (depuis C++11) |
| thread(const thread&) = delete; |
(4) | (depuis C++11) |
Construit objet nouveau thread .
Original:
Constructs new thread object.
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.
1)
Crée un objet nouveau thread qui ne représente pas un fil .
Original:
Creates new thread object which does not represent a 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.
2)
Déplacez constructeur. Construit l'objet thread pour représenter le thread d'exécution qui a été représenté par
other. Après cet appel other ne représente plus un thread d'exécution .Original:
Move constructor. Constructs the thread object to represent the thread of execution that was represented by
other. After this call other no longer represents a thread of execution.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.
3)
Crée un nouveau
std::thread objet et l'associe à un thread d'exécution. D'abord le constructeur de copie toutes args... arguments pour stockage local des threads comme par la fonction:Original:
Creates new
std::thread object and associates it with a thread of execution. First the constructor copies all arguments args... to thread-local storage as if by the function: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.
template <class T> typename decay<T>::type decay_copy(T&& v) { return std::forward<T>(v); }
@ @ Toutes les exceptions levées lors de l'évaluation et de la copie des arguments sont jetés dans le thread en cours, et non pas le nouveau thread .
Original:
@@ Any exceptions thrown during evaluation and copying of the arguments are thrown in the current thread, not the new 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.
@ @ Le code qui sera exécuté dans le nouveau thread est défini comme suit.
Nous allons consulter None
copied_args comme t1, t2, ..., tN, où N est sizeof...(copied_args)and
copied_args is the result of calling decay_copy as defined above. The following code will be run in the new thread:Original:
Let's refer to None
copied_args as t1, t2, ..., tN, where N is sizeof...(copied_args)and copied_args is the result of calling decay_copy as defined above. The following code will be run in the new 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.
- Si
fest un pointeur vers une fonction membre de la classeT, il est alors appelé. La valeur de retour est ignorée. En effet, le code suivant est exécuté:Original:Iffis pointer to a member function of classT, then it is called. The return value is ignored. Effectively, the following code is executed:The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
- (t1.*f)(t2, ..., tN) si le type de
t1est soitT, la référence àTou de référence à taper dérivé deT.Original:(t1.*f)(t2, ..., tN) if the type oft1is eitherT, reference toTor reference to type derived fromT.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - ((*t1).*f)(t2, ..., tN) autrement .Original:((*t1).*f)(t2, ..., tN) otherwise.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
-
- Si N == 1 et
fest pointeur vers un objet membre de données d'une classe, il est alors accessible. La valeur de l'objet est ignoré. En effet, le code suivant est exécuté:Original:If N == 1 andfis pointer to a member data object of a class, then it is accessed. The value of the object is ignored. Effectively, the following code is executed:The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
- Si t1.*f et du type de
t1est soitT, ou référence àTréférence au type dérivé deT.Original:t1.*f if and the type oft1is eitherT, reference toTor reference to type derived fromT.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - (*t1).*f autrement .Original:(*t1).*f otherwise.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
-
-
fest appelé comme un pointeur vers une fonction non-membre dans les autres cas. La valeur de retour est ignorée. En effet, f(t1, t2, ..., tN) est exécuté .Original:fis called as a pointer to a non-member function in all other cases. The return value is ignored. Effectively, f(t1, t2, ..., tN) is executed.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Original:
@@ The code that will be run in the new thread is defined as follows.
Nous allons consulter None
copied_args comme t1, t2, ..., tN, où N est sizeof...(copied_args)and
copied_args is the result of calling decay_copy as defined above. The following code will be run in the new thread:Original:
Let's refer to None
copied_args as t1, t2, ..., tN, where N is sizeof...(copied_args)and copied_args is the result of calling decay_copy as defined above. The following code will be run in the new 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.
- Si
fest un pointeur vers une fonction membre de la classeT, il est alors appelé. La valeur de retour est ignorée. En effet, le code suivant est exécuté:Original:Iffis pointer to a member function of classT, then it is called. The return value is ignored. Effectively, the following code is executed:The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
- (t1.*f)(t2, ..., tN) si le type de
t1est soitT, la référence àTou de référence à taper dérivé deT.Original:(t1.*f)(t2, ..., tN) if the type oft1is eitherT, reference toTor reference to type derived fromT.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - ((*t1).*f)(t2, ..., tN) autrement .Original:((*t1).*f)(t2, ..., tN) otherwise.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
-
- Si N == 1 et
fest pointeur vers un objet membre de données d'une classe, il est alors accessible. La valeur de l'objet est ignoré. En effet, le code suivant est exécuté:Original:If N == 1 andfis pointer to a member data object of a class, then it is accessed. The value of the object is ignored. Effectively, the following code is executed:The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
- Si t1.*f et du type de
t1est soitT, ou référence àTréférence au type dérivé deT.Original:t1.*f if and the type oft1is eitherT, reference toTor reference to type derived fromT.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - (*t1).*f autrement .Original:(*t1).*f otherwise.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
-
-
fest appelé comme un pointeur vers une fonction non-membre dans les autres cas. La valeur de retour est ignorée. En effet, f(t1, t2, ..., tN) est exécuté .Original:fis called as a pointer to a non-member function in all other cases. The return value is ignored. Effectively, f(t1, t2, ..., tN) is executed.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
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.
4)
Le constructeur de copie est supprimée; fils ne sont pas copiable. Il n'ya pas deux
std::thread objets peuvent représenter le même thread d'exécution .Original:
The copy constructor is deleted; threads are not copyable. No two
std::thread objects may represent the same thread of execution.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.
Sommaire |
[modifier] Paramètres
| other | - | un autre objet thread pour construire cet objet thread avec
Original: another thread object to construct this thread object with The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
| f | - | fonctionner à exécuter dans le nouveau thread
Original: function to execute in the new thread The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
| args... | - | arguments à passer à la nouvelle fonction
Original: arguments to pass to the new function The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
[modifier] Exceptions
1-2)
3)
std::system_error si le thread n'a pas pu être démarré. L'exception peut représenter le
std::errc::resource_unavailable_try_again condition d'erreur ou d'une autre condition d'erreur spécifique à l'implémentation .Original:
std::system_error if the thread could not be started. The exception may represent the error condition
std::errc::resource_unavailable_try_again or another implementation-specific error condition.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.
[modifier] Notes
Les arguments de la fonction de thread sont copiées par valeur. Si un argument de référence doit être passé à la fonction de thread, il doit être enveloppé (par exemple avec std::ref ou std::cref) .
Original:
The arguments to the thread function are copied by value. If a reference argument needs to be passed to the thread function, it has to be wrapped (e.g. with std::ref or std::cref).
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.
Toute valeur de retour de la fonction est ignorée. Si la fonction lève une exception, std::terminate est appelée. Afin de passer des valeurs de retour ou des exceptions au thread, appelez ou std::promise std::async peut être utilisé .
Original:
Any return value from the function is ignored. If the function throws an exception, std::terminate is called. In order to pass return values or exceptions back to the calling thread, std::promise or std::async may be used.
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.
[modifier] Exemple
#include <iostream> #include <utility> #include <thread> #include <chrono> #include <functional> #include <atomic> void f1(int n) { for(int i=0; i<5; ++i) { std::cout << "Thread " << n << " executing\n"; std::this_thread::sleep_for(std::chrono::milliseconds(10)); } } void f2(int& n) { for(int i=0; i<5; ++i) { std::cout << "Thread 2 executing\n"; ++n; std::this_thread::sleep_for(std::chrono::milliseconds(10)); } } int main() { int n = 0; std::thread t1; // t1 is not a thread std::thread t2(f1, n+1); // pass by value std::thread t3(f2, std::ref(n)); // pass by reference std::thread t4(std::move(t3)); // t4 is now running f2(). t3 is no longer a thread t2.join(); t4.join(); std::cout << "Final value of n is " << n << '\n'; }
Résultat possible :
Thread 1 executing Thread 2 executing Thread 1 executing Thread 2 executing Thread 1 executing Thread 2 executing Thread 1 executing Thread 2 executing Thread 1 executing Thread 2 executing Final value of n is 5

