The Boost.Thread library specification for the move constructor states for
移动构造函数的Boost.Thread库规范说明
Move Constructor:
移动构造函数:
Effects: Transfers ownership of the thread managed by other (if any) to the newly constructed boost::thread instance.
效果:将由其他(如果有)管理的线程的所有权转移到新构造的boost :: thread实例。
whereas for Move Assignment :
而对于移动分配:
Transfers ownership of the thread managed by other (if any) to *this. If there was a thread previously associated with *this then that thread is detached.
将其他(如果有)管理的线程的所有权转移给* this。如果有一个先前与* this相关联的线程,那么该线程将被分离。
Clearly, for move assignment it is explicitly stated that previous thread object becomes detached.
显然,对于移动分配,明确声明先前的线程对象变得分离。
Since the copying of boost::thread object has not been defined, and only moving of ownership is possible, does this mean that with Move Constructor, the previous owner thread does not become detached?
由于尚未定义boost :: thread对象的复制,并且只能移动所有权,这是否意味着使用Move Constructor,以前的所有者线程不会分离?
Or is this simply a documentation oversight?
或者这只是一个文件疏忽?
3 个解决方案
#1
6
You're misunderstanding. Label your thread objects A and B, and the actual thread T.
你是误会。标记线程对象A和B,以及实际线程T.
If B owns T, move constructing A from B means A now owns T, and B owns nothing.
If B owns T, move assigning A from B means A now owns T, and B owns nothing, and whatever A had previously owned is not owned by anything (aka, detached).
如果B拥有T,则从B移动构造A意味着A现在拥有T,而B不拥有任何东西。如果B拥有T,则移动从B分配A意味着A现在拥有T,B不拥有任何东西,并且A先前拥有的东西不归任何东西(又名,分离)。
#2
4
It's a move-constructor -- what previous owner can there be if the object is just coming into existence?
它是一个移动构造函数 - 如果对象刚刚存在,那么以前的所有者可以存在什么?
#3
3
The difference is that when move constructing, the new thread object didn't exist before, so it has no previous thread.
不同之处在于,当移动构造时,新的线程对象之前不存在,因此它没有先前的线程。
When move assigning, you start with two thread objects and end with at least one of them being empty.
移动分配时,从两个线程对象开始,最后至少有一个为空。
#1
6
You're misunderstanding. Label your thread objects A and B, and the actual thread T.
你是误会。标记线程对象A和B,以及实际线程T.
If B owns T, move constructing A from B means A now owns T, and B owns nothing.
If B owns T, move assigning A from B means A now owns T, and B owns nothing, and whatever A had previously owned is not owned by anything (aka, detached).
如果B拥有T,则从B移动构造A意味着A现在拥有T,而B不拥有任何东西。如果B拥有T,则移动从B分配A意味着A现在拥有T,B不拥有任何东西,并且A先前拥有的东西不归任何东西(又名,分离)。
#2
4
It's a move-constructor -- what previous owner can there be if the object is just coming into existence?
它是一个移动构造函数 - 如果对象刚刚存在,那么以前的所有者可以存在什么?
#3
3
The difference is that when move constructing, the new thread object didn't exist before, so it has no previous thread.
不同之处在于,当移动构造时,新的线程对象之前不存在,因此它没有先前的线程。
When move assigning, you start with two thread objects and end with at least one of them being empty.
移动分配时,从两个线程对象开始,最后至少有一个为空。