|
Boost : |
Subject: [boost] [thread] Passing function with parameters to boost::barrier
From: André Offringa (offringa_at_[hidden])
Date: 2019-01-31 14:08:21
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é
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk