Я попытался вызвать функцию с параметрами, используя boost, но это не сработает. код этоПараметры функции связывания для потока
void Simulate::cr_number_threaded(lint nodes) {
for(lint i = 0; i < trials_per_thread; i++) {
// code
}
}
void Simulate::run_cr_number() {
vec_cr_number.clear();
boost::thread t[threads];
for(int i = 0; i < n_s.size(); i++) {
// n_s[i] is the current number of nodes
for(int t_idx = 0; t_idx < threads; t_idx++)
t[t_idx] = boost::thread(cr_number_threaded, n_s[i]);
// etc...
}
}
ошибка, я получаю следующее:
Simulate.cpp: In member function 'void Simulate::run_cr_number()': Simulate.cpp:27: error: no matching function for call to 'boost::thread::thread(, long int&)'
UPDATE: Я последовал за предложения. Используя первое решение, которое я получить
Simulate.cpp: In member function 'void Simulate::run_cr_number()': Simulate.cpp:28: error: no matching function for call to 'bind(, long int&)' ../../boost_1_44_0/boost/bind/bind.hpp:1472: note: candidates are: boost::_bi::bind_t::type> boost::bind(F, A1) [with F = void (Simulate::*)(lint), A1 = long int] ../../boost_1_44_0/boost/bind/bind.hpp:1728: note:
boost::_bi::bind_t::type, boost::_mfi::dm, typename boost::_bi::list_av_1::type> boost::bind(M T::*, A1) [with A1 = long int, M = void()(lint), T = Simulate]
используя второй я получаю это вместо
Simulate.cpp: In member function 'void Simulate::run_cr_number()': Simulate.cpp:28: error: no matching function for call to 'boost::thread::swap(boost::_bi::bind_t, boost::_bi::list2, boost::_bi::value > >)' ../../boost_1_44_0/boost/thread/detail/thread.hpp:310: note: candidates are: void boost::thread::swap(boost::thread&)
'cr_number_threaded' - это функция-член, поэтому вам нужно передать экземпляр и полностью квалифицировать его имя:' boost :: bind (& Simulate :: cr_number_threaded, this, n_s [i]) '. –
Я обновил вопрос, с некоторыми результатами – Bob
Я не получаю ошибки компиляции, используя это: t [t_idx] = boost :: thread (& Simulate :: cr_number_threaded, this, n_s [i]); – Bob