Opened 14 years ago

Closed 13 years ago

#2742 closed Patches (fixed)

Why the at_thread_exit cleanup function is const?

Reported by: viboes Owned by: Anthony Williams
Milestone: Boost 1.39.0 Component: thread
Version: Boost 1.37.0 Severity: Problem
Keywords: at_thread_exit Cc:

Description

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?

Attachments (3)

thread.hpp (15.5 KB ) - added by anonymous 13 years ago.
2742.patch (587 bytes ) - added by viboes 13 years ago.
test_ticket_2742.cpp (896 bytes ) - added by viboes 13 years ago.

Download all attachments as: .zip

Change History (6)

by anonymous, 13 years ago

Attachment: thread.hpp added

by viboes, 13 years ago

Attachment: 2742.patch added

by viboes, 13 years ago

Attachment: test_ticket_2742.cpp added

comment:1 by viboes, 13 years ago

The attached files contains the test showing the bug and a patch solving the issue

comment:2 by viboes, 13 years ago

Type: BugsPatches

comment:3 by Anthony Williams, 13 years ago

Resolution: fixed
Status: newclosed

Fixed on trunk

Note: See TracTickets for help on using tickets.