我正在使用boost::thread
从同一类的不同成员函数内调用类内成员函数。我想线程方法的声明是:boost ::线程类内成员函数调用返回unique_lock实例化错误
void ClassName::nnMetropolisStep(double random, std::vector<int> nums);
而且我通过创建从另一个成员函数线程:
boost::thread* tThread = new boost::thread(&ClassName::nnMetropolisStep,
this,
someRandom,someNums);
这些都是在代码中我唯一的调用boost
功能使用。
我在其他问题中看到这种语法将适用于非静态成员函数(并且我没有构建线程的方式没有访问问题)。但是,当我编译时,出现以下错误:
g++ -fPIC -std=c++11 -c -g -Wall `root-config --cflags --glibs` -MMD -c -o obj/IsingModel.o src/IsingModel.cpp
In file included from /usr/include/boost/thread/pthread/mutex.hpp:11:0,
from /usr/include/boost/thread/mutex.hpp:16,
from /usr/include/boost/thread/pthread/thread_data.hpp:12,
from /usr/include/boost/thread/thread.hpp:17,
from /usr/include/boost/thread.hpp:13,
from src/interface/IsingModel.h:11,
from src/IsingModel.cpp:11:
/usr/include/boost/thread/locks.hpp: In instantiation of 'boost::unique_lock<Mutex>& boost::unique_lock<Mutex>::operator=(boost::unique_lock<Mutex>&&) [with Mutex = boost::mutex]':
/usr/include/boost/thread/future.hpp:414:33: required from here
/usr/include/boost/thread/locks.hpp:269:22: error: cannot bind 'boost::unique_lock<boost::mutex>' lvalue to 'boost::unique_lock<boost::mutex>&&'
swap(temp);
^
/usr/include/boost/thread/locks.hpp:279:14: note: initializing argument 1 of 'void boost::unique_lock<Mutex>::swap(boost::unique_lock<Mutex>&&) [with Mutex = boost::mutex]'
void swap(unique_lock&& other)
^
make: *** [obj/IsingModel.o] Error 1
这是怎么回事?很明显,我要么做的不正确,或者更糟糕的是,我的编译器设置存在问题。
由于boost :: unique_lock,您正在收到错误。不是由于你在这里提到的代码。 – Sumeet
@Sumeet是的,但为什么我会没有任何明确的电话或包括unique_lock吗? –