Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于SyncQueue.hpp中的Take(std::list<T> list)方法的std::move操作 #18

Open
kangyijie5473 opened this issue Jul 26, 2017 · 3 comments

Comments

@kangyijie5473
Copy link

您好,看了您的书依然对于std::move这部分不是很理解
在SyncQueue.hpp 第34行 list = std::move(m_queue) 之后对于m_queue没有任何操作,我认为这样做,之后的线程再对m_queue进行的操作都会导致错误,因为这时的m_queue已经变成了 'list' 交给工作线程去处理了,所以应该更新m_queue。。我还没想好应该怎样去更新,也不知道自己的想法是否正确。。希望您能解答我的疑问。

@qicosmos
Copy link
Owner

对m_queue的访问都是线程安全的,不需要去更新。move之后queue实际上在那个时刻是空的,后面的线程会根据条件变量来判断queue是否是空的,空的就会等待,非空就会去去数据。

@kangyijie5473
Copy link
Author

我自己又写了个例子,的确不用更新。但是对std::move不是很理解
我之前理解std::move就是将一个左值转换为右值引用,不太清楚原来的左值发生了什么变化。包括我在看《C++ Primer》时, 如果进行int &&rr3 = std::move(rr1)这样一个调用之后,只能对rr1进行赋值和销毁操作。那么rr1或者说这个m_queue在进行std::move之后发生了什么变化呢?
希望您能解答。

@qicosmos
Copy link
Owner

move之后,queue就变空了。建议你看一下c++11的移动语义。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants