Boost logo

Boost :

From: Anthony Williams (anthony_w.geo_at_[hidden])
Date: 2008-05-19 16:47:19


"vicente.botet" <vicente.botet_at_[hidden]> writes:

> In the Join library I have see the following idiom
>
> mutex mtx;
> condition_variable cond;
> unsigned num_blocked;
>
> void foo() {
> unique_lock l(mtx);
> ++num_blocked;
> cond.wait(lock);
> --num_blocked;
>
> // ...
> }
>
> void foo() {
> unique_lock l(mtx);
> // ...
> if (num_blocked > 0) cond.notify_one();
> // ...
> }
>
> Does this perform better in some contexts? if yes in which ones?

It really shouldn't do. The check is part of the notify.

Anthony

-- 
Anthony Williams            | Just Software Solutions Ltd
Custom Software Development | http://www.justsoftwaresolutions.co.uk
Registered in England, Company Number 5478976.
Registered Office: 15 Carrallack Mews, St Just, Cornwall, TR19 7UL

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