原文地址:http://www.cplusplus.com/reference/thread/thread/operator=/
public member function
<thread>
std::thread::operator=
move (1)
thread& operator= (thread&& rhs) noexcept;
|
copy [deleted] (2)
thread& operator= (const thread&) = delete;
|
Move-assign thread
If the object is currently notjoinable, it acquires the thread of execution represented byrhs(if
any).
如果对象现在是非joinable,将获取rhs的执行线程。
If it isjoinable,terminate()
is
called.
如果是joinable,将调用terminate().
After the call,rhsno longer represents any thread of execution (as ifdefault-constructed).
调用之后,rhs不再执行任何线程。
threadobjects cannot be copied(2).
线程对象不能被复制。
Parameters
rhs
threadobject whose state is moved to*this
.
将被移动到现在线程的线程rhs.
Return value
*this
返回该线程。
Example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
// example for thread::operator=
#include <iostream> // std::cout
#include <thread> // std::thread, std::this_thread::sleep_for
#include <chrono> // std::chrono::seconds
void pause_thread(int n)
{
std::this_thread::sleep_for (std::chrono::seconds(n));
std::cout << "pause of " << n << " seconds ended\n";
}
int main()
{
std::thread threads[5]; // default-constructed threads
std::cout << "Spawning 5 threads...\n";
for (int i=0; i<5; ++i)
threads[i] = std::thread(pause_thread,i+1); // move-assign threads
std::cout << "Done spawning threads. Now waiting for them to join:\n";
for (int i=0; i<5; ++i)
threads[i].join();
std::cout << "All threads joined!\n";
return 0;
}
|
|
Output (after 5 seconds):
Spawning 5 threads...
Done spawning threads. Now waiting for them to join:
pause of 1 seconds ended
pause of 2 seconds ended
pause of 3 seconds ended
pause of 4 seconds ended
pause of 5 seconds ended
All threads joined!
|
Data races
Bothrhsand the object are modified.
Exception safety
No-throw guarantee:never throws exceptions.
—————————————————————————————————————————————————————————————————
//写的错误或者不好的地方请多多指导,可以在下面留言或者点击左上方邮件地址给我发邮件,指出我的错误以及不足,以便我修改,更好的分享给大家,谢谢。
转载请注明出处:http://blog.csdn.net/qq844352155
author:天下无双
Email:coderguang@gmail.com
2014-9-4
于GDUT
——————————————————————————————————————————————————————————————————
分享到:
相关推荐
线程调用类对象 在前面的示例中,我们为... void operator()() { std::cout << functor\n; } }; int main() { MyFunctor fnctor; std::thread t(fnctor); std::cout << main thread\n; t.join();
c++11多线程操作 线程 thread int main() { thread t1(Test1); t1.join(); thread t2(Test2); t2.join(); thread t3 = t1; thread t4(t1); thread t5 = std::move(t1); thread t6(std::move(t1)); ...
线程安全队列的接口文件如下: #include ... threadsafe_queue& operator=(const threadsafe_queue&) = delete; void push(T new_value); bool try_pop(T& value); std::shared_ptr<T> try_po
首先看看boost::thread的构造函数吧,boost::thread有两个构造函数: (1)thread():构造一个表示当前执行线程的线程对象; (2)explicit thread(const boost::function0& threadfunc): boost::function0可以...
2.1.2 Compatibility between C++98 and C++11 . . . . . . . . . . . . . . . . . 9 2.2 Complexity and Big-O Notation . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 3 New LanguageFeatures 13 3.1...
Classes Inheritance Multiple Inheritance Interfaces Operator Overloading Access Control Declaration Order Write Short Functions Google-Specific Magic Smart Pointers cpplint Other C++ Features ...
string threadIdStr = Long::toString(Thread::currentThread()->getId()); // Create a messages string text = (string) "Hello world! from thread " + threadIdStr; for (int ix = 0; ix ; ++ix) { std::...
7 绑定函数到Lua 为了绑定函数到Lua,你可以使用函数 luabind::def(). 它的声明如下: template, class policies> void def(const char* name, F f, const Policies&); * name 是该函数在Lua里面的名字 * F 是该函数...
该资源不适合C、C++初学者,可作为C++高手向大师级进化的参考书。 内容: ... 17 Library introduction 17.1 General 17.2 The C standard library 17.3 Definitions 17.4 Additional definitions 17.5 ...
11 4.7 Multi-threaded executions and data races . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 4.8 Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ...
11 October 2006. Summary of changes for version 20061011: 1) ACPI CA Core Subsystem: Completed an AML interpreter performance enhancement for control method execution. Previously a 2-pass parse/...
stdafx.h的代码// This is a part of the Microsoft Foundation Classes C++ library. // Copyright (C) 1992-1998 Microsoft Corporation // All rights reserved. // // This source code is only intended as a ...
1.7 The C++ memory model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 1.8 The C++ object model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ...
Frame 7范例程序 Command Routing(命令传递) Frame 8范例程序 本章回顾 第二篇 欲善工事先利其器 第4章 Visual C++集成开发环境 安装与组成 四个重要的工具 内务府总管:Visual C++集成开发环境 关于project 关于...
operator《和operator》 效率考虑 自定SERIAL宏给抽象类使用 在CObList中加入CStroke以外的类 Document与View交流——为Step4做准备 第9章 消息映射与命令传递 到底要解决什么 消息分类 万流归宗Command Target...
operator《和operator》 效率考虑 自定SERIAL宏给抽象类使用 在CObList中加入CStroke以外的类 Document与View交流——为Step4做准备 第9章 消息映射与命令传递 到底要解决什么 消息分类 万流归宗Command Target...
11 33 44 Ci CiCiCiCirc rcrcrcrcle lelelele Re ReReReRect ctctctct 66 55 77 St StStStStro rorororoke kekekeke 圖 2c /圖 2b程式碼所製造的結果。 Boxing和 Un-boxing帶來的影響 前面曾經說...
The compiler supports Object Pascal language based on the Delphi 7 standard and extends it with generic types, operator overloading, anonymous functions and closures, lambda-expressions. Syntax of ...
The compiler supports Object Pascal language based on the Delphi 7 standard and extends it with generic types, operator overloading, anonymous functions and closures, lambda-expressions. Syntax of ...
Chapter 7: Memory Management and Pointers 187 Memory Management under the Hood 187 Value Data Types 188 Reference Data Types 190 Garbage Collection 192 Freeing Unmanaged Resources 193 Destructors 193 ...