我正在尝试将其编译为嵌入式项目,但始终无法编译。在Mac上使用clang可以正确编译代码。
该示例基本上将2个线程添加到双端队列容器,将它们加入并从容器中删除。更新
class th {
public:
void func() {
sleep(3);
*this->progress = 100;
}
th(int* prog) :
progress(prog),
m_thread(std::thread(&th::func, this)) {};
th(th const& other) = delete;
th(th && other) = default;
th& operator=(th const& other) = delete;
th& operator=(th &&) = default;
void join() { m_thread.join(); }
int *progress;
private:
std::thread m_thread;
};
int main(void) {
std::vector<int> progress;
progress.push_back(-1);
progress.push_back(-1);
std::deque<std::unique_ptr<th>> deq;
std::cout << "progress[0]:" << progress[0] << std::endl;
std::cout << "progress[1]:" << progress[1] << std::endl;
std::cout << "executing threads..." << std::endl;
for(size_t i = 0; i < 2; ++i) {
deq.push_back(std::unique_ptr<th>(new th(&progress[i])));
}
while(true) {
std::cout << "SIZE:" << deq.size() << std::endl;
if(deq.size() == 0)
break;
for (std::deque<std::unique_ptr<th>>::iterator it = deq.begin(); it != deq.end(); it++) {
//std::cout << (*it)->progress << std::endl;
if(*((*it)->progress) == 100) {
std::cout << "JOIN & DELETE" << std::endl;
(*it)->join();
deq.erase(it);
}
else {
std::cout << "STILL RUNNING" << std::endl;
}
//std::cout << *((*it)->progress) << std::endl;
}
sleep(1);
}
exit(EXIT_SUCCESS);
}
UPDATED-编译器消息:
In file included from /ti-sdk-am335x-evm-05.04.01.00/linux-devkit/bin/../lib/gcc/arm-arago-linux-gnueabi/4.5.3/../../../../arm-arago-linux-gnueabi/include/c++/4.5.3/bits/concept_check.h:55:0,
from /ti-sdk-am335x-evm-05.04.01.00/linux-devkit/bin/../lib/gcc/arm-arago-linux-gnueabi/4.5.3/../../../../arm-arago-linux-gnueabi/include/c++/4.5.3/bits/move.h:35,
from /ti-sdk-am335x-evm-05.04.01.00/linux-devkit/bin/../lib/gcc/arm-arago-linux-gnueabi/4.5.3/../../../../arm-arago-linux-gnueabi/include/c++/4.5.3/bits/stl_pair.h:60,
from /ti-sdk-am335x-evm-05.04.01.00/linux-devkit/bin/../lib/gcc/arm-arago-linux-gnueabi/4.5.3/../../../../arm-arago-linux-gnueabi/include/c++/4.5.3/bits/stl_algobase.h:66,
from /ti-sdk-am335x-evm-05.04.01.00/linux-devkit/bin/../lib/gcc/arm-arago-linux-gnueabi/4.5.3/../../../../arm-arago-linux-gnueabi/include/c++/4.5.3/bits/char_traits.h:41,
from /ti-sdk-am335x-evm-05.04.01.00/linux-devkit/bin/../lib/gcc/arm-arago-linux-gnueabi/4.5.3/../../../../arm-arago-linux-gnueabi/include/c++/4.5.3/ios:41,
from /ti-sdk-am335x-evm-05.04.01.00/linux-devkit/bin/../lib/gcc/arm-arago-linux-gnueabi/4.5.3/../../../../arm-arago-linux-gnueabi/include/c++/4.5.3/ostream:40,
from /ti-sdk-am335x-evm-05.04.01.00/linux-devkit/bin/../lib/gcc/arm-arago-linux-gnueabi/4.5.3/../../../../arm-arago-linux-gnueabi/include/c++/4.5.3/iostream:40,
from /home/user/test/app/ato/main.cpp:1:
/ti-sdk-am335x-evm-05.04.01.00/linux-devkit/bin/../lib/gcc/arm-arago-linux-gnueabi/4.5.3/../../../../arm-arago-linux-gnueabi/include/c++/4.5.3/bits/unique_ptr.h: In member function 'void __gnu_cxx::_SGIAssignableConcept<_Tp>::__constraints() [with _Tp = std::unique_ptr<th>]':
/ti-sdk-am335x-evm-05.04.01.00/linux-devkit/bin/../lib/gcc/arm-arago-linux-gnueabi/4.5.3/../../../../arm-arago-linux-gnueabi/include/c++/4.5.3/bits/stl_deque.h:717:1: instantiated from 'std::deque<std::unique_ptr<th> >'
/home/user/test/app/ato/main.cpp:55:35: instantiated from here
/ti-sdk-am335x-evm-05.04.01.00/linux-devkit/bin/../lib/gcc/arm-arago-linux-gnueabi/4.5.3/../../../../arm-arago-linux-gnueabi/include/c++/4.5.3/bits/unique_ptr.h:207:7: error: deleted function 'std::unique_ptr<_Tp, _Tp_Deleter>::unique_ptr(const std::unique_ptr<_Tp, _Tp_Deleter>&) [with _Tp = th, _Tp_Deleter = std::default_delete<th>, std::unique_ptr<_Tp, _Tp_Deleter> = std::unique_ptr<th>]'
/ti-sdk-am335x-evm-05.04.01.00/linux-devkit/bin/../lib/gcc/arm-arago-linux-gnueabi/4.5.3/../../../../arm-arago-linux-gnueabi/include/c++/4.5.3/bits/boost_concept_check.h:203:28: error: used here
/ti-sdk-am335x-evm-05.04.01.00/linux-devkit/bin/../lib/gcc/arm-arago-linux-gnueabi/4.5.3/../../../../arm-arago-linux-gnueabi/include/c++/4.5.3/bits/unique_ptr.h:208:19: error: deleted function 'std::unique_ptr<_Tp, _Tp_Deleter>& std::unique_ptr<_Tp, _Tp_Deleter>::operator=(const std::unique_ptr<_Tp, _Tp_Deleter>&) [with _Tp = th, _Tp_Deleter = std::default_delete<th>, std::unique_ptr<_Tp, _Tp_Deleter> = std::unique_ptr<th>]'
/ti-sdk-am335x-evm-05.04.01.00/linux-devkit/bin/../lib/gcc/arm-arago-linux-gnueabi/4.5.3/../../../../arm-arago-linux-gnueabi/include/c++/4.5.3/bits/boost_concept_check.h:204:7: error: used here
/ti-sdk-am335x-evm-05.04.01.00/linux-devkit/bin/../lib/gcc/arm-arago-linux-gnueabi/4.5.3/../../../../arm-arago-linux-gnueabi/include/c++/4.5.3/bits/unique_ptr.h: In member function 'void __gnu_cxx::_SGIAssignableConcept<_Tp>::__const_constraints(const _Tp&) [with _Tp = std::unique_ptr<th>]':
/ti-sdk-am335x-evm-05.04.01.00/linux-devkit/bin/../lib/gcc/arm-arago-linux-gnueabi/4.5.3/../../../../arm-arago-linux-gnueabi/include/c++/4.5.3/bits/boost_concept_check.h:205:7: instantiated from 'void __gnu_cxx::_SGIAssignableConcept<_Tp>::__constraints() [with _Tp = std::unique_ptr<th>]'
/ti-sdk-am335x-evm-05.04.01.00/linux-devkit/bin/../lib/gcc/arm-arago-linux-gnueabi/4.5.3/../../../../arm-arago-linux-gnueabi/include/c++/4.5.3/bits/stl_deque.h:717:1: instantiated from 'std::deque<std::unique_ptr<th> >'
/home/user/test/app/ato/main.cpp:55:35: instantiated from here
/ti-sdk-am335x-evm-05.04.01.00/linux-devkit/bin/../lib/gcc/arm-arago-linux-gnueabi/4.5.3/../../../../arm-arago-linux-gnueabi/include/c++/4.5.3/bits/unique_ptr.h:207:7: error: deleted function 'std::unique_ptr<_Tp, _Tp_Deleter>::unique_ptr(const std::unique_ptr<_Tp, _Tp_Deleter>&) [with _Tp = th, _Tp_Deleter = std::default_delete<th>, std::unique_ptr<_Tp, _Tp_Deleter> = std::unique_ptr<th>]'
/ti-sdk-am335x-evm-05.04.01.00/linux-devkit/bin/../lib/gcc/arm-arago-linux-gnueabi/4.5.3/../../../../arm-arago-linux-gnueabi/include/c++/4.5.3/bits/boost_concept_check.h:208:28: error: used here
/ti-sdk-am335x-evm-05.04.01.00/linux-devkit/bin/../lib/gcc/arm-arago-linux-gnueabi/4.5.3/../../../../arm-arago-linux-gnueabi/include/c++/4.5.3/bits/unique_ptr.h:208:19: error: deleted function 'std::unique_ptr<_Tp, _Tp_Deleter>& std::unique_ptr<_Tp, _Tp_Deleter>::operator=(const std::unique_ptr<_Tp, _Tp_Deleter>&) [with _Tp = th, _Tp_Deleter = std::default_delete<th>, std::unique_ptr<_Tp, _Tp_Deleter> = std::unique_ptr<th>]'
/ti-sdk-am335x-evm-05.04.01.00/linux-devkit/bin/../lib/gcc/arm-arago-linux-gnueabi/4.5.3/../../../../arm-arago-linux-gnueabi/include/c++/4.5.3/bits/boost_concept_check.h:209:7: error: used here
/ti-sdk-am335x-evm-05.04.01.00/linux-devkit/bin/../lib/gcc/arm-arago-linux-gnueabi/4.5.3/../../../../arm-arago-linux-gnueabi/include/c++/4.5.3/bits/unique_ptr.h: In member function 'void __gnu_cxx::_Mutable_BidirectionalIteratorConcept<_Tp>::__constraints() [with _Tp = std::unique_ptr<th>*]':
/ti-sdk-am335x-evm-05.04.01.00/linux-devkit/bin/../lib/gcc/arm-arago-linux-gnueabi/4.5.3/../../../../arm-arago-linux-gnueabi/include/c++/4.5.3/bits/boost_concept_check.h:57:50: instantiated from 'void __gnu_cxx::__function_requires() [with _Concept = __gnu_cxx::_Mutable_BidirectionalIteratorConcept<std::unique_ptr<th>*>]'
/ti-sdk-am335x-evm-05.04.01.00/linux-devkit/bin/../lib/gcc/arm-arago-linux-gnueabi/4.5.3/../../../../arm-arago-linux-gnueabi/include/c++/4.5.3/bits/stl_algobase.h:673:7: instantiated from '_BI2 std::move_backward(_BI1, _BI1, _BI2) [with _BI1 = std::unique_ptr<th>*, _BI2 = std::unique_ptr<th>*]'
/ti-sdk-am335x-evm-05.04.01.00/linux-devkit/bin/../lib/gcc/arm-arago-linux-gnueabi/4.5.3/../../../../arm-arago-linux-gnueabi/include/c++/4.5.3/bits/deque.tcc:978:4: instantiated from 'std::_Deque_iterator<_Tp, _Tp&, _Tp*> std::move_backward(std::_Deque_iterator<_Tp, const _Tp&, const _Tp*>, std::_Deque_iterator<_Tp, const _Tp&, const _Tp*>, std::_Deque_iterator<_Tp, _Tp&, _Tp*>) [with _Tp = std::unique_ptr<th>]'
/ti-sdk-am335x-evm-05.04.01.00/linux-devkit/bin/../lib/gcc/arm-arago-linux-gnueabi/4.5.3/../../../../arm-arago-linux-gnueabi/include/c++/4.5.3/bits/stl_deque.h:422:13: instantiated from 'std::_Deque_iterator<_Tp, _Tp&, _Tp*> std::move_backward(std::_Deque_iterator<_Tp, _Tp&, _Tp*>, std::_Deque_iterator<_Tp, _Tp&, _Tp*>, std::_Deque_iterator<_Tp, _Tp&, _Tp*>) [with _Tp = std::unique_ptr<th>]'
/ti-sdk-am335x-evm-05.04.01.00/linux-devkit/bin/../lib/gcc/arm-arago-linux-gnueabi/4.5.3/../../../../arm-arago-linux-gnueabi/include/c++/4.5.3/bits/deque.tcc:174:6: instantiated from 'std::deque<_Tp, _Alloc>::iterator std::deque<_Tp, _Alloc>::erase(std::deque<_Tp, _Alloc>::iterator) [with _Tp = std::unique_ptr<th>, _Alloc = std::allocator<std::unique_ptr<th> >, std::deque<_Tp, _Alloc>::iterator = std::_Deque_iterator<std::unique_ptr<th>, std::unique_ptr<th>&, std::unique_ptr<th>*>]'
/home/user/test/app/ato/main.cpp:97:18: instantiated from here
/ti-sdk-am335x-evm-05.04.01.00/linux-devkit/bin/../lib/gcc/arm-arago-linux-gnueabi/4.5.3/../../../../arm-arago-linux-gnueabi/include/c++/4.5.3/bits/unique_ptr.h:208:19: error: deleted function 'std::unique_ptr<_Tp, _Tp_Deleter>& std::unique_ptr<_Tp, _Tp_Deleter>::operator=(const std::unique_ptr<_Tp, _Tp_Deleter>&) [with _Tp = th, _Tp_Deleter = std::default_delete<th>, std::unique_ptr<_Tp, _Tp_Deleter> = std::unique_ptr<th>]'
/ti-sdk-am335x-evm-05.04.01.00/linux-devkit/bin/../lib/gcc/arm-arago-linux-gnueabi/4.5.3/../../../../arm-arago-linux-gnueabi/include/c++/4.5.3/bits/boost_concept_check.h:513:7: error: used here
/ti-sdk-am335x-evm-05.04.01.00/linux-devkit/bin/../lib/gcc/arm-arago-linux-gnueabi/4.5.3/../../../../arm-arago-linux-gnueabi/include/c++/4.5.3/bits/unique_ptr.h: In member function 'void __gnu_cxx::_ConvertibleConcept<_From, _To>::__constraints() [with _From = std::unique_ptr<th>, _To = std::unique_ptr<th>]':
/ti-sdk-am335x-evm-05.04.01.00/linux-devkit/bin/../lib/gcc/arm-arago-linux-gnueabi/4.5.3/../../../../arm-arago-linux-gnueabi/include/c++/4.5.3/bits/boost_concept_check.h:57:50: instantiated from 'void __gnu_cxx::__function_requires() [with _Concept = __gnu_cxx::_ConvertibleConcept<std::unique_ptr<th>, std::unique_ptr<th> >]'
/ti-sdk-am335x-evm-05.04.01.00/linux-devkit/bin/../lib/gcc/arm-arago-linux-gnueabi/4.5.3/../../../../arm-arago-linux-gnueabi/include/c++/4.5.3/bits/stl_algobase.h:674:7: instantiated from '_BI2 std::move_backward(_BI1, _BI1, _BI2) [with _BI1 = std::unique_ptr<th>*, _BI2 = std::unique_ptr<th>*]'
/ti-sdk-am335x-evm-05.04.01.00/linux-devkit/bin/../lib/gcc/arm-arago-linux-gnueabi/4.5.3/../../../../arm-arago-linux-gnueabi/include/c++/4.5.3/bits/deque.tcc:978:4: instantiated from 'std::_Deque_iterator<_Tp, _Tp&, _Tp*> std::move_backward(std::_Deque_iterator<_Tp, const _Tp&, const _Tp*>, std::_Deque_iterator<_Tp, const _Tp&, const _Tp*>, std::_Deque_iterator<_Tp, _Tp&, _Tp*>) [with _Tp = std::unique_ptr<th>]'
/ti-sdk-am335x-evm-05.04.01.00/linux-devkit/bin/../lib/gcc/arm-arago-linux-gnueabi/4.5.3/../../../../arm-arago-linux-gnueabi/include/c++/4.5.3/bits/stl_deque.h:422:13: instantiated from 'std::_Deque_iterator<_Tp, _Tp&, _Tp*> std::move_backward(std::_Deque_iterator<_Tp, _Tp&, _Tp*>, std::_Deque_iterator<_Tp, _Tp&, _Tp*>, std::_Deque_iterator<_Tp, _Tp&, _Tp*>) [with _Tp = std::unique_ptr<th>]'
/ti-sdk-am335x-evm-05.04.01.00/linux-devkit/bin/../lib/gcc/arm-arago-linux-gnueabi/4.5.3/../../../../arm-arago-linux-gnueabi/include/c++/4.5.3/bits/deque.tcc:174:6: instantiated from 'std::deque<_Tp, _Alloc>::iterator std::deque<_Tp, _Alloc>::erase(std::deque<_Tp, _Alloc>::iterator) [with _Tp = std::unique_ptr<th>, _Alloc = std::allocator<std::unique_ptr<th> >, std::deque<_Tp, _Alloc>::iterator = std::_Deque_iterator<std::unique_ptr<th>, std::unique_ptr<th>&, std::unique_ptr<th>*>]'
/home/user/test/app/ato/main.cpp:97:18: instantiated from here
/ti-sdk-am335x-evm-05.04.01.00/linux-devkit/bin/../lib/gcc/arm-arago-linux-gnueabi/4.5.3/../../../../arm-arago-linux-gnueabi/include/c++/4.5.3/bits/unique_ptr.h:207:7: error: deleted function 'std::unique_ptr<_Tp, _Tp_Deleter>::unique_ptr(const std::unique_ptr<_Tp, _Tp_Deleter>&) [with _Tp = th, _Tp_Deleter = std::default_delete<th>, std::unique_ptr<_Tp, _Tp_Deleter> = std::unique_ptr<th>]'
/ti-sdk-am335x-evm-05.04.01.00/linux-devkit/bin/../lib/gcc/arm-arago-linux-gnueabi/4.5.3/../../../../arm-arago-linux-gnueabi/include/c++/4.5.3/bits/boost_concept_check.h:218:27: error: used here
/ti-sdk-am335x-evm-05.04.01.00/linux-devkit/bin/../lib/gcc/arm-arago-linux-gnueabi/4.5.3/../../../../arm-arago-linux-gnueabi/include/c++/4.5.3/bits/unique_ptr.h: In member function 'void __gnu_cxx::_OutputIteratorConcept<_Tp, _ValueT>::__constraints() [with _Tp = std::unique_ptr<th>*, _ValueT = std::unique_ptr<th>]':
/ti-sdk-am335x-evm-05.04.01.00/linux-devkit/bin/../lib/gcc/arm-arago-linux-gnueabi/4.5.3/../../../../arm-arago-linux-gnueabi/include/c++/4.5.3/bits/boost_concept_check.h:57:50: instantiated from 'void __gnu_cxx::__function_requires() [with _Concept = __gnu_cxx::_OutputIteratorConcept<std::unique_ptr<th>*, std::unique_ptr<th> >]'
/ti-sdk-am335x-evm-05.04.01.00/linux-devkit/bin/../lib/gcc/arm-arago-linux-gnueabi/4.5.3/../../../../arm-arago-linux-gnueabi/include/c++/4.5.3/bits/stl_algobase.h:501:7: instantiated from '_OI std::move(_II, _II, _OI) [with _II = std::unique_ptr<th>*, _OI = std::unique_ptr<th>*]'
/ti-sdk-am335x-evm-05.04.01.00/linux-devkit/bin/../lib/gcc/arm-arago-linux-gnueabi/4.5.3/../../../../arm-arago-linux-gnueabi/include/c++/4.5.3/bits/deque.tcc:939:4: instantiated from 'std::_Deque_iterator<_Tp, _Tp&, _Tp*> std::move(std::_Deque_iterator<_Tp, const _Tp&, const _Tp*>, std::_Deque_iterator<_Tp, const _Tp&, const _Tp*>, std::_Deque_iterator<_Tp, _Tp&, _Tp*>) [with _Tp = std::unique_ptr<th>]'
/ti-sdk-am335x-evm-05.04.01.00/linux-devkit/bin/../lib/gcc/arm-arago-linux-gnueabi/4.5.3/../../../../arm-arago-linux-gnueabi/include/c++/4.5.3/bits/stl_deque.h:405:18: instantiated from 'std::_Deque_iterator<_Tp, _Tp&, _Tp*> std::move(std::_Deque_iterator<_Tp, _Tp&, _Tp*>, std::_Deque_iterator<_Tp, _Tp&, _Tp*>, std::_Deque_iterator<_Tp, _Tp&, _Tp*>) [with _Tp = std::unique_ptr<th>]'
/ti-sdk-am335x-evm-05.04.01.00/linux-devkit/bin/../lib/gcc/arm-arago-linux-gnueabi/4.5.3/../../../../arm-arago-linux-gnueabi/include/c++/4.5.3/bits/deque.tcc:180:6: instantiated from 'std::deque<_Tp, _Alloc>::iterator std::deque<_Tp, _Alloc>::erase(std::deque<_Tp, _Alloc>::iterator) [with _Tp = std::unique_ptr<th>, _Alloc = std::allocator<std::unique_ptr<th> >, std::deque<_Tp, _Alloc>::iterator = std::_Deque_iterator<std::unique_ptr<th>, std::unique_ptr<th>&, std::unique_ptr<th>*>]'
/home/user/test/app/ato/main.cpp:97:18: instantiated from here
/ti-sdk-am335x-evm-05.04.01.00/linux-devkit/bin/../lib/gcc/arm-arago-linux-gnueabi/4.5.3/../../../../arm-arago-linux-gnueabi/include/c++/4.5.3/bits/unique_ptr.h:208:19: error: deleted function 'std::unique_ptr<_Tp, _Tp_Deleter>& std::unique_ptr<_Tp, _Tp_Deleter>::operator=(const std::unique_ptr<_Tp, _Tp_Deleter>&) [with _Tp = th, _Tp_Deleter = std::default_delete<th>, std::unique_ptr<_Tp, _Tp_Deleter> = std::unique_ptr<th>]'
/ti-sdk-am335x-evm-05.04.01.00/linux-devkit/bin/../lib/gcc/arm-arago-linux-gnueabi/4.5.3/../../../../arm-arago-linux-gnueabi/include/c++/4.5.3/bits/boost_concept_check.h:462:7: error: used here
/ti-sdk-am335x-evm-05.04.01.00/linux-devkit/bin/../lib/gcc/arm-arago-linux-gnueabi/4.5.3/../../../../arm-arago-linux-gnueabi/include/c++/4.5.3/bits/unique_ptr.h: In member function 'void __gnu_cxx::_Mutable_ForwardIteratorConcept<_Tp>::__constraints() [with _Tp = std::unique_ptr<th>*]':
/ti-sdk-am335x-evm-05.04.01.00/linux-devkit/bin/../lib/gcc/arm-arago-linux-gnueabi/4.5.3/../../../../arm-arago-linux-gnueabi/include/c++/4.5.3/bits/boost_concept_check.h:57:50: instantiated from 'void __gnu_cxx::__function_requires() [with _Concept = __gnu_cxx::_Mutable_ForwardIteratorConcept<std::unique_ptr<th>*>]'
/ti-sdk-am335x-evm-05.04.01.00/linux-devkit/bin/../lib/gcc/arm-arago-linux-gnueabi/4.5.3/../../../../arm-arago-linux-gnueabi/include/c++/4.5.3/bits/boost_concept_check.h:512:7: instantiated from 'void __gnu_cxx::_Mutable_BidirectionalIteratorConcept<_Tp>::__constraints() [with _Tp = std::unique_ptr<th>*]'
/ti-sdk-am335x-evm-05.04.01.00/linux-devkit/bin/../lib/gcc/arm-arago-linux-gnueabi/4.5.3/../../../../arm-arago-linux-gnueabi/include/c++/4.5.3/bits/boost_concept_check.h:57:50: instantiated from 'void __gnu_cxx::__function_requires() [with _Concept = __gnu_cxx::_Mutable_BidirectionalIteratorConcept<std::unique_ptr<th>*>]'
/ti-sdk-am335x-evm-05.04.01.00/linux-devkit/bin/../lib/gcc/arm-arago-linux-gnueabi/4.5.3/../../../../arm-arago-linux-gnueabi/include/c++/4.5.3/bits/stl_algobase.h:673:7: instantiated from '_BI2 std::move_backward(_BI1, _BI1, _BI2) [with _BI1 = std::unique_ptr<th>*, _BI2 = std::unique_ptr<th>*]'
/ti-sdk-am335x-evm-05.04.01.00/linux-devkit/bin/../lib/gcc/arm-arago-linux-gnueabi/4.5.3/../../../../arm-arago-linux-gnueabi/include/c++/4.5.3/bits/deque.tcc:978:4: instantiated from 'std::_Deque_iterator<_Tp, _Tp&, _Tp*> std::move_backward(std::_Deque_iterator<_Tp, const _Tp&, const _Tp*>, std::_Deque_iterator<_Tp, const _Tp&, const _Tp*>, std::_Deque_iterator<_Tp, _Tp&, _Tp*>) [with _Tp = std::unique_ptr<th>]'
/ti-sdk-am335x-evm-05.04.01.00/linux-devkit/bin/../lib/gcc/arm-arago-linux-gnueabi/4.5.3/../../../../arm-arago-linux-gnueabi/include/c++/4.5.3/bits/stl_deque.h:422:13: instantiated from 'std::_Deque_iterator<_Tp, _Tp&, _Tp*> std::move_backward(std::_Deque_iterator<_Tp, _Tp&, _Tp*>, std::_Deque_iterator<_Tp, _Tp&, _Tp*>, std::_Deque_iterator<_Tp, _Tp&, _Tp*>) [with _Tp = std::unique_ptr<th>]'
/ti-sdk-am335x-evm-05.04.01.00/linux-devkit/bin/../lib/gcc/arm-arago-linux-gnueabi/4.5.3/../../../../arm-arago-linux-gnueabi/include/c++/4.5.3/bits/deque.tcc:174:6: instantiated from 'std::deque<_Tp, _Alloc>::iterator std::deque<_Tp, _Alloc>::erase(std::deque<_Tp, _Alloc>::iterator) [with _Tp = std::unique_ptr<th>, _Alloc = std::allocator<std::unique_ptr<th> >, std::deque<_Tp, _Alloc>::iterator = std::_Deque_iterator<std::unique_ptr<th>, std::unique_ptr<th>&, std::unique_ptr<th>*>]'
/home/user/test/app/ato/main.cpp:97:18: instantiated from here
/ti-sdk-am335x-evm-05.04.01.00/linux-devkit/bin/../lib/gcc/arm-arago-linux-gnueabi/4.5.3/../../../../arm-arago-linux-gnueabi/include/c++/4.5.3/bits/unique_ptr.h:208:19: error: deleted function 'std::unique_ptr<_Tp, _Tp_Deleter>& std::unique_ptr<_Tp, _Tp_Deleter>::operator=(const std::unique_ptr<_Tp, _Tp_Deleter>&) [with _Tp = th, _Tp_Deleter = std::default_delete<th>, std::unique_ptr<_Tp, _Tp_Deleter> = std::unique_ptr<th>]'
/ti-sdk-am335x-evm-05.04.01.00/linux-devkit/bin/../lib/gcc/arm-arago-linux-gnueabi/4.5.3/../../../../arm-arago-linux-gnueabi/include/c++/4.5.3/bits/boost_concept_check.h:488:7: error: used here
make: *** [/home/user/test/obj/main.o] Error 1
最佳答案
问题是您的班级不可移动。我可以理解,由于该类具有std::thread
,因此您希望避免默认的复制行为,但是我看不出该类不可移动的任何原因。如果启用移动构造和分配your code works fine。
th(th const& other) = delete;
th(th && other) = default;
th& operator=(th const& other) = delete;
th& operator=(th &&) = default;
我也会根据以下内容调整您构建这些对象的方式
for(size_t i = 0; i < 2; ++i) {
deq.push_back(std::make_unique<th>(&progress[i]));
}
关于c++ - 与线程包装的unique_ptr进行双端队列,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41366632/