Boost logo

Boost :

Subject: Re: [boost] [threads / signals2] Win events replace by boost signals (threadsafe)
From: Fu ji (fujimailing_at_[hidden])
Date: 2015-03-25 03:57:05


I read about condition variable and it's also not the best idea, because we
can receive signal only if we actually wait in this time. For example:

void setcondvar()
{
    boost::this_thread::sleep_for(boost::chrono::milliseconds(200));
    std::cout << "Set" << std::endl;
    cond.notify_all();
    std::cout << "After" << std::endl;
}

int main()
{
    boost::mutex CondMutex;

    boost::thread t1(setcondvar);
    t1.join();

    std::cout << "Before wait" << std::endl;

    boost::unique_lock<boost::mutex> lock(CondMutex);
    bool result = cond.timed_wait(lock,
boost::posix_time::milliseconds(1000));

    std::cout << result;

return 0;
}

and we have 0 as result. Probably i should write some wrapper on cond
variable if i would like to have this functionality.

2015-03-24 23:40 GMT+01:00 Gavin Lambert <gavinl_at_[hidden]>:

> On 24/03/2015 22:28, Fu ji wrote:
>
>> Condition variable can be a really good solution to my problem, I have
>> only
>> problem with WaitForMultipleObjects because with cond_var I have to check
>> all "events" in loop with cond.timed_wait. There is a better solution ?
>>
>
> If the events are intended to signal that data is available somewhere,
> then you could consider replacing them with futures instead, which can
> supply the data at the same time. There is a way to wait for one or all of
> a set of multiple futures, although not with a timeout.
>
>
>
>
> _______________________________________________
> Unsubscribe & other changes: http://lists.boost.org/
> mailman/listinfo.cgi/boost
>


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk