Boost logo

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::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
()>&>(boost::detail::nullary_function<void ()>&) (
 Â Â Â  this=0x7fffff7ff0c0, f=...) at

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?


Boost list run by bdawes at, gregod at, cpdaniel at, john at