Swiftslide
September 5th, 2010, 12:55 PM
I'm just learning boost and multithreading in general. In my project I have a class called "HarbourMaster" (it is a boat simulation), which needs to create three threads of functions that belong to it. The functions are named "passTime()", "checkLoadingBays()" and "checkUnloadingBays()".
I have tried to create these threads in several ways. The first is following the syntax provided in my reference material:
boost::thread timeThread(&passTime);
boost::thread lBaysThread(&checkLoadingBays);
boost::thread uBaysThread(&checkUnloadingBays);
But the references seemingly don't apply for class functions; I get the following errors, once for each thread:
ISO C++ forbids taking the address of an unqualified or parenthesized non-static member function to form a pointer to member function. Say ‘&HarbourMaster::passTime’
ISO C++ forbids taking the address of an unqualified or parenthesized non-static member function to form a pointer to member function. Say ‘&HarbourMaster::checkLoadingBays’
ISO C++ forbids taking the address of an unqualified or parenthesized non-static member function to form a pointer to member function. Say ‘&HarbourMaster::checkUnloadingBays’
So despite all my past experiences with the C++ compiler I decide to follow its advice:
boost::thread timeThread(&HarbourMaster::passTime);
boost::thread lBaysThread(&HarbourMaster::checkLoadingBays);
boost::thread uBaysThread(&HarbourMaster::checkUnloadingBays);
Of course, I get another error - though only one this time:
In file included from /usr/include/boost/thread/thread.hpp:22,
/usr/include/boost/thread/detail/thread.hpp:56: error: must use ‘.*’ or ‘->*’ to call pointer-to-member function in ‘((boost::detail::thread_data<void (HarbourMaster::*)()>*)this)->boost::detail::thread_data<void (HarbourMaster::*)()>::f (...)’, e.g. ‘(... ->* ((boost::detail::thread_data<void (HarbourMaster::*)()>*)this)->boost::detail::thread_data<void (HarbourMaster::*)()>::f) (...)’
I tried understanding this, but failed miserably. So I started messing around trying random ways of writing the statement, looking at the error, and trying to figure out what random way to try next. I've been trying for forty-five minutes now and decided that it's rather pointless. Could anyone please tell me how I'm supposed to create a thread? I would love you forever, but in a totally non-invasive way.
Thanks
I have tried to create these threads in several ways. The first is following the syntax provided in my reference material:
boost::thread timeThread(&passTime);
boost::thread lBaysThread(&checkLoadingBays);
boost::thread uBaysThread(&checkUnloadingBays);
But the references seemingly don't apply for class functions; I get the following errors, once for each thread:
ISO C++ forbids taking the address of an unqualified or parenthesized non-static member function to form a pointer to member function. Say ‘&HarbourMaster::passTime’
ISO C++ forbids taking the address of an unqualified or parenthesized non-static member function to form a pointer to member function. Say ‘&HarbourMaster::checkLoadingBays’
ISO C++ forbids taking the address of an unqualified or parenthesized non-static member function to form a pointer to member function. Say ‘&HarbourMaster::checkUnloadingBays’
So despite all my past experiences with the C++ compiler I decide to follow its advice:
boost::thread timeThread(&HarbourMaster::passTime);
boost::thread lBaysThread(&HarbourMaster::checkLoadingBays);
boost::thread uBaysThread(&HarbourMaster::checkUnloadingBays);
Of course, I get another error - though only one this time:
In file included from /usr/include/boost/thread/thread.hpp:22,
/usr/include/boost/thread/detail/thread.hpp:56: error: must use ‘.*’ or ‘->*’ to call pointer-to-member function in ‘((boost::detail::thread_data<void (HarbourMaster::*)()>*)this)->boost::detail::thread_data<void (HarbourMaster::*)()>::f (...)’, e.g. ‘(... ->* ((boost::detail::thread_data<void (HarbourMaster::*)()>*)this)->boost::detail::thread_data<void (HarbourMaster::*)()>::f) (...)’
I tried understanding this, but failed miserably. So I started messing around trying random ways of writing the statement, looking at the error, and trying to figure out what random way to try next. I've been trying for forty-five minutes now and decided that it's rather pointless. Could anyone please tell me how I'm supposed to create a thread? I would love you forever, but in a totally non-invasive way.
Thanks