[thread] Why the at_thread_exit cleanup function be const?

In addition, if a remove the const on operator()() struct mycallable1 { void operator()() { std::cout << "mycallable1" << std::endl; }; }; void my_thread() { std::cout << "my_thread" << std::endl; mycallable1 x; boost::this_thread::at_thread_exit(x); } I get the following error: gcc.compile.c++ ..\..\..\bin.v2\libs\interthreads\test\hello_world.test\gcc-4.3.2\debug\target-os-cygwin\threadapi-pthread\threading-multi\hello_world.o ../../../boost/thread/detail/thread.hpp: In member function `void boost::detail::thread_exit_function<F>::operator()() const [with F = mycallable1]': ..\example\hello_world.cpp:52: instantiated from here ../../../boost/thread/detail/thread.hpp:474: error: passing `const mycallable1' as `this' argument of `void mycallable1::operator()()' discards qualifiers Why the cleanup function must be const? Best, Vicente ______________________ Vicente Juan Botet Escribá

Hello, I first posted this two months ago, allow me to repost just in case it went unnoticed: ----- Original Message ----- From: "vicente.botet" <vicente.botet@wanadoo.fr> To: <boost@lists.boost.org> Sent: Monday, November 10, 2008 5:37 PM Subject: [boost] [thread] Why the at_thread_exit cleanup function is const? If I remove the const on operator()() struct mycallable1 { void operator()() { std::cout << "mycallable1" << std::endl; }; }; void my_thread() { std::cout << "my_thread" << std::endl; mycallable1 x; boost::this_thread::at_thread_exit(x); } I get the following error: gcc.compile.c++ ..\..\..\bin.v2\libs\interthreads\test\hello_world.test\gcc-4.3.2\debug\target-os-cygwin\threadapi-pthread\threading-multi\hello_world.o ../../../boost/thread/detail/thread.hpp: In member function `void boost::detail::thread_exit_function<F>::operator()() const [with F = mycallable1]': ..\example\hello_world.cpp:52: instantiated from here ../../../boost/thread/detail/thread.hpp:474: error: passing `const mycallable1' as `this' argument of `void mycallable1::operator()()' discards qualifiers Why the cleanup function must be const? Best, Vicente ______________________ Vicente Juan Botet Escribá _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

"vicente.botet" <vicente.botet@wanadoo.fr> writes:
Hello, I first posted this two months ago, allow me to repost just in case it went unnoticed:
Sorry for the lack of response.
From: "vicente.botet" <vicente.botet@wanadoo.fr>
If I remove the const on operator()() struct mycallable1 { void operator()() { std::cout << "mycallable1" << std::endl; }; };
void my_thread() { std::cout << "my_thread" << std::endl; mycallable1 x; boost::this_thread::at_thread_exit(x); }
I get the following error:
gcc.compile.c++ ..\..\..\bin.v2\libs\interthreads\test\hello_world.test\gcc-4.3.2\debug\target-os-cygwin\threadapi-pthread\threading-multi\hello_world.o ../../../boost/thread/detail/thread.hpp: In member function `void boost::detail::thread_exit_function<F>::operator()() const [with F = mycallable1]': ..\example\hello_world.cpp:52: instantiated from here ../../../boost/thread/detail/thread.hpp:474: error: passing `const mycallable1' as `this' argument of `void mycallable1::operator()()' discards qualifiers
Why the cleanup function must be const?
I can't think of a good reason just now. Anthony -- Anthony Williams Author of C++ Concurrency in Action | http://www.manning.com/williams just::thread C++0x thread library | http://www.stdthread.co.uk Custom Software Development | http://www.justsoftwaresolutions.co.uk Just Software Solutions Ltd, Registered in England, Company Number 5478976. Registered Office: 15 Carrallack Mews, St Just, Cornwall, TR19 7UL, UK
participants (2)
-
Anthony Williams
-
vicente.botet