boost::signals + pthreads = seg fault on Linux
Hi, I have a problem with boost::signals when I try to use them in multi threaded projects. I have tried gcc 3.2.3 and gcc 3.3.2, on two different Linux boxes, with the same result. The following test program works fine w/o threads and crashes after the 17th call to connect if I add -pthread to the compile command: #include <boost/signal.hpp> void on_do_something () { } int main () { boost::signal<void ()> sig; for (int i = 0; i < 100; ++i) sig.connect (&on_do_something); } I have tried electric fence, then it crashes immediatly in the first call to pthread_mutex_init, but I can't see any reason for that crash with gdb. Once again, even with electric fence, everything works fine w/o threads, so I see no mem corruption or any reason why it should not work _with_ threads. Any idea? Thanks Uwe
Uwe Sander wrote:
Hi,
I have a problem with boost::signals when I try to use them in multi threaded projects. I have tried gcc 3.2.3 and gcc 3.3.2, on two different Linux boxes, with the same result. The following test program works fine w/o threads and crashes after the 17th call to connect if I add -pthread to the compile command:
The first pitfall I hit using signals in a multi-threaded environment is that the signals lib by default (on win32 anyway) builds a single threaded library, NOT multi-threaded. You have to explicitly force a multi-threaded build for it using <threading>multi as a BUILD option of bjam. HTH Russell
Hi (again), Am Donnerstag, 8. Januar 2004 19:00 schrieb Russell Hind:
The first pitfall I hit using signals in a multi-threaded environment is that the signals lib by default (on win32 anyway) builds a single threaded library, NOT multi-threaded. You have to explicitly force a multi-threaded build for it using
<threading>multi
as a BUILD option of bjam.
HTH
Indeed, at least the demo code I have sent in works w/o any trouble now, thank you :-) I will try our project at work tomorrow and report back if there are still problems. BTW, I could not find this build option in the boost docs; am I blind? Thanks again Uwe
Uwe Sander wrote:
Indeed, at least the demo code I have sent in works w/o any trouble now, thank you :-) I will try our project at work tomorrow and report back if there are still problems. BTW, I could not find this build option in the boost docs; am I blind?
I haven't had much success understanding the build docs either, someone posted a simple link ages ago for me to build with borland which was bjam -sTOOLS=borland -sBUILD="release <threading>multi <runtime-link>static" (or something like that). I haven't tried any other configurations. I have now created my own C++BuilderX project file for building the libraries I use so no-longer use bjam anyway. Thanks Russell
participants (2)
-
Russell Hind
-
Uwe Sander