Here is my class.h
class threads_queue{
private:
boost::condition_variable the_condition_variable;
public:
//boost::atomic<bool> done;
boost::lockfree::spsc_queue<std::pair<char, std::string>> q{100};
//threads_queue() : done(false) {};
void static run_function();
void add_query(std::string, std::string);
void get_query(void);
};
& Here is class.cpp
void threads_queue::get_query(void){
std::pair<char, std::string> value;
//to do..
}
void threads_queue::add_query(std::string str, std::string work){
//to do ..
}
void run_function(){
//Here I want to create two threads
//First thread like
boost::thread producer_thread(add_query);
boost::thread consumer_thread(get_query);
producer_thread.join();
//done = true;
consumer_thread.join()
}
I'm following this example: http://www.boost.org/doc/libs/1_54_0/doc/html/lockfree/examples.html
But the problem is when I want to create a thread I always get an error, it does not work
Here were my attempts to solve the error:
1.
boost::thread consumer_thread(&threads_queue::get_query);
I got this error:
Called object type 'void (threads_queue::*)()' is not a function or function pointer
2.
boost::thread consumer_thread(&threads_queue::get_query, this);
I got this error:
Invalid use of 'this' outside of a non-static member function
3.
boost::thread* thr = new boost::thread(boost::bind(&threads_queue::get_query));
I got this error:
/usr/local/include/boost/bind/bind.hpp:75:22: Type 'void (threads_queue::*)()' cannot be used prior to '::' because it has no members
I am not how could this problem be solved, any help?
UPDATE This topic has great discussion of the problem: Using boost thread and a non-static class function
My main problem was I forgot to add
threads_queue::
before the run() in my cpp file, there are Mikhail comments below where were a great help: .