Boost logo

Threads-Devel :

Subject: Re: [Threads-devel] may be a bug in boost.thread on freebsd 8.0
From: Anthony Williams (anthony_at_[hidden])
Date: 2010-07-28 09:23:45


On 28/07/10 13:15, å×ÇÅÎÉÊ ûÕÂÉÎ wrote:
> I use boost1.43 on freebsd8.0 amd64, installed from ports.
> Here is a simple program that causes an assertion:
>
> Assertion failed: (!pthread_cond_wait(&cond,m.mutex()->native_handle())), function wait, file ./boost/thread/pthread/condition_variable.hpp, line 20.
>
> during execution.
>
> #include<boost/thread.hpp>
> #include<cstdlib>
>
> using namespace std;
>
> void ThreadFun(int number)
> {
> sleep(5);
> }
>
> int main(int argc, char** argv)
> {
> if (argc> 1)
> {
> pid_t pid = fork();
> if (pid< 0)
> {
> return EXIT_FAILURE;
> }
> else if (pid> 0)
> {
> return EXIT_SUCCESS;
> }
> }
> boost::thread th1(boost::bind(&ThreadFun, 1));
> th1.join();
> return EXIT_SUCCESS;
> }
>
> Error occurs only when I execute program with command line arguments(when the process forks)
> and only on freebsd 8.0 (on ubuntu 10.04 x64 and on freebsd 7.3 amd 64 it works correct).
>
> Is it a bug or did something wrong?

Looks to me like fork() doesn't interact well with the thread library on
freebsd 8.0 --- does it work if you use raw POSIX threads and condition
variables?

Since you create the thread AFTER the fork, it would suggest to me that
the library isn't correctly initialized when forking.

Anthony

-- 
Author of C++ Concurrency in Action     http://www.stdthread.co.uk/book/
just::thread C++0x thread library             http://www.stdthread.co.uk
Just Software Solutions Ltd       http://www.justsoftwaresolutions.co.uk
15 Carrallack Mews, St Just, Cornwall, TR19 7UL, UK. Company No. 5478976

Threads-Devel list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk