English 中文(简体)
在C++11中,“不代表执行线”的透镜是什么?
原标题:In C++11, what is the point of a thread which "does not represent a thread of execution"?

看看C++11中新的透镜,看看看它如何轻易地向胎面绘制地图,我注意到thread的构造区中的曲线部分:

thread();
Effects: Constructs a thread object that does not represent a thread of execution.
Postcondition: get_id() == id()
Throws: Nothing.

换言之,read的构造者实际上似乎在create 深处。 很显然,它创造了一个read子:object,,但如果它没有背书,那么究竟是多么有用? 还有某种其他方式,例如thrd.start(<>/code>或其他类似内容?

最佳回答

还有某种其他方式可以把“执行线”放在该物体上,例如第th.start()或类似的东西?

// deferred start
std::thread thread;

// ...

// let s start now
thread = std::thread(functor, arg0, arg1);

<代码>std:thread is a MoveConstructible and MoveAssignable category. 因此,这意味着,在像<条码”这样的代码中:th(有些是functor); st: steal(std:move(zombie));>zombie将留有特殊但有效的国家,与没有执行线有关。 违约构造从某种意义上说是自由的,因为它必须做的是将目标置于这一准确状态。 还可提供<代码>std:thread和std:vector<std:thread>:resize

问题回答

It means the same thing as this:

 std::vector<int> emptyList;

<密码>yList是空的。 就像一个缺建的<代码>std:thread。 就像一个缺建的<代码>std:ofstream。 无文件。 有完全合理的理由将违约的班级变成空洞的国家。


如果是空洞的:

std::thread myThread;

确实,你可以这样做:

myThread = std::thread(f, ...);

在<代码>f为一些可打电话的物品(功能点、轨迹、<代码>std:, 等)和<代码>......为拟转交深层的论据。

不仅仅是猜测:

"thread object" refers to a std::thread.

http://en.wikipedia.org/wiki/Thread_%28computer_science%29”rel=“noreferer” 代表深层的硬件登记册的收集。

C++11 is doing nothing but papering over the OS s API for access to OS threads in order to make C++ threading portable across all OS s.

thread();
Effects: Constructs a thread object that does not represent a thread of execution.
Postcondition: get_id() == id()
Throws: Nothing.

这意味着修建的“<代码>std:thread <>/code> 并没有提到本处所生产的执行线。

A std::thread can be given a new value, and thus begin to refer to an OS thread of execution by a move assignment statement:

std::thread t;  // Does not refer to an OS thread
//...
t = std::thread(my_func);  // t refers to the OS thread executing my_func

进行公正的猜测,但这只是意味着read不开始。 换言之,它只是一个与其他目标一样的物体,不一定是实际的顾问。 另一种方式是,如果read在胎面顶上实施,则制造一个C++11型read子,必然会称作read-(create)——只有在read开始的时候才需要。





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签