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 11:35:25


I tried previous example with condition variable:

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

using namespace std;

pthread_cond_t thread_flag_cv;
pthread_mutex_t thread_flag_mutex;

void* ThreadFun(void*)
{
    assert(!pthread_mutex_lock (&thread_flag_mutex));
    assert(!pthread_cond_wait (&thread_flag_cv, &thread_flag_mutex));
    assert(!pthread_mutex_unlock (&thread_flag_mutex));

    sleep(5);
}

int main(int argc, char** argv)
{
    pthread_mutex_init (&thread_flag_mutex, NULL);
    pthread_cond_init (&thread_flag_cv, NULL);

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

    sleep(5);
    assert(!pthread_mutex_lock (&thread_flag_mutex));
    assert(!pthread_cond_signal (&thread_flag_cv));
    assert(!pthread_mutex_unlock (&thread_flag_mutex));

    assert(!pthread_join(thread_handle, 0));
    return 0;
}

The result is the same. It works correct. Do I use cond variable in the same way as in boost.thread one is used?
How could I commit a patch to repository, if I will fix the bug?

Wed, 28 Jul 2010 15:47:46 +0100 ÐÉÓØÍÏ ÏÔ Anthony Williams <anthony_at_[hidden]>:

> On 28/07/10 15:09, å×ÇÅÎÉÊ ûÕÂÉÎ wrote:
> > I have tried using raw pthread and it works fine. Here is a sample code:
>
> [snip]
>
> > But there is no usage of condition variable.
>
> Do pthread condition variables work with fork()?
>
> > I see no reason using it in such simple task like thread joining.
>
> They are used by boost.thread to enable timed_join.
>
> > Should I dive into source code of boost.thread(pthread/thread.cpp) to solve this problem?
>
> If you like.
>
> 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