Boost logo

Boost Users :

Subject: Re: [Boost-users] Conditional thread join
From: Chris (cmrchs_at_[hidden])
Date: 2010-11-23 03:10:17


Hello.

condition variables OK but then my actual problem is that the Read-
function is already waiting for
data to arrive using a condition variable something like:

void Read()
 {
    bool end_loop = false;
    do
    {
        scoped_lock<interprocess_mutex> lock(recvChannel->_mutex);

        // wait for data to arrive
        recvChannel->_condition.wait(lock);
        end_loop = (std::strcmp(recvChannel->_data, "X") == 0);

        if ( ! end_loop)
            std::cout << recvChannel->_data << "\n>";
    } while (!end_loop);
} // Read()

Normally in my scenario, another process notifies Read() by sending
data.
But Ok, within the same process I could wake it up notifying channel2
as well

As a general question then, is it possible to wait
for more than 1 condition in a OR like fashion or something ?

thank you

On Nov 23, 3:47 am, David Abrahams <d..._at_[hidden]> wrote:
> At Mon, 22 Nov 2010 16:12:22 -0800 (PST),
>
>
>
> Chris wrote:
>
> > No, I want to stop when either thread finishes
> > something like a join_any(). Does that exist?
>
> > greetings
> > Chris
>
> >    } while (...);
> > }  // Write()
>
> > boost::thread thrd1(Read);
> > boost::thread thrd2(Write);
>
> > // I don't want the following
> > thrd1.join();
> > thrd2.join();
>
> > No, I want to stop when either thread finishes
> > something like a conditional join. Does that exist?
>
> Sounds like a job for condition variables.
>
> --
> Dave Abrahams
> BoostPro Computinghttp://www.boostpro.com
>
> _______________________________________________
> Boost-users mailing list
> Boost-us..._at_[hidden]http://lists.boost.org/mailman/listinfo.cgi/boost-users


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net