我正在使用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嗎? –