Boost logo

Threads-Devel :

Subject: Re: [Threads-devel] may be a bug in boost.thread on freebsd 8.0
From: å×ÇÅÎÉÊ ûÕÂÉÎ (shubin_evgeniy_at_[hidden])
Date: 2010-07-28 10:09:17


I have tried using raw pthread and it works fine. Here is a sample code:

#include <pthread.h>
#include <unistd.h>
#include <assert.h>

using namespace std;

void* ThreadFun(void*)
{
        sleep(5);
}

int main(int argc, char** argv)
{
    if (argc > 1)
    {
        pid_t pid = fork();
        if (pid < 0)
        {
            return 1;
        }
        else if (pid > 0)
        {
            return 0;
        }
    }
    pthread_attr_t t_attr;
    assert(!pthread_attr_init(&t_attr));
    assert(!pthread_attr_setdetachstate(&t_attr, PTHREAD_CREATE_JOINABLE));
    pthread_t thread_handle;
    assert(!pthread_create(&thread_handle, &t_attr, &ThreadFun, 0));
    assert(!pthread_join(thread_handle, 0));
    return 0;
}

But there is no usage of condition variable.
I see no reason using it in such simple task like thread joining.
Should I dive into source code of boost.thread(pthread/thread.cpp) to solve this problem?
Has anyone tried this code on freebsd 8.0?

Thanks.

Wed, 28 Jul 2010 14:23:45 +0100 ÐÉÓØÍÏ ÏÔ Anthony Williams <anthony_at_[hidden]>:

>
> 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