[thread] Passing function with parameters to boost::barrier

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[thread] Passing function with parameters to boost::barrier

Boost - Dev mailing list
Hi Boost developers,

I'm having a problem with passing a completion function to a
boost::barrier, causing a segfault, and I suspect it is a bug in the
barrier code. The following is a minimal example that shows the problem:

#include <boost/thread/barrier.hpp>

void func(int)
{
}

int main()
{
   boost::barrier b(1, std::bind(func, 42));
   b.wait();
}

Running inside gdb and doing a bt shows some infinite recursion
happening, starting with:
#0  0x000055555555e41a in
boost::thread_detail::decay_copy<boost::detail::nullary_function<void
()>&>(boost::detail::nullary_function<void ()>&) (
     t=<error reading variable: Cannot access memory at address
0x7fffff7feff0>) at /usr/include/boost/thread/detail/move.hpp:355
#1  0x000055555555d814 in boost::detail::nullary_function<void
()>::nullary_function<boost::detail::nullary_function<void
()>&>(boost::detail::nullary_function<void ()>&) (
     this=0x7fffff7ff0c0, f=...) at
/usr/include/boost/thread/detail/nullary_function.hpp:81
...

When I change "std::bind(func, 42)" to just "func" (and declare func
without parameters), it does work and the program exits normally.
Passing a lambda to barrier (e.g. barrier(1, [&]() { func(0); } ) )
causes the same segfault, and the same holds when I change std::bind to
boost::bind. I'm using Boost 1.67 on Debian Linux, amd64, gcc 8.2.0. Is
this a bug?

Cheers,
André

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Reply | Threaded
Open this post in threaded view
|

Re: [thread] Passing function with parameters to boost::barrier

Boost - Dev mailing list
AMDG

On 1/31/19 7:08 AM, André Offringa via Boost wrote:
>
> I'm having a problem with passing a completion function to a
> boost::barrier, causing a segfault, and I suspect it is a bug in the
> barrier code. The following is a minimal example that shows the problem:
>

This appears to be fixed recently:
https://svn.boost.org/trac10/ticket/13561

In Christ,
Steven Watanabe

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost