Boost logo

Boost Users :

Subject: Re: [Boost-users] [thread] release lock before cond.var. notified?
From: Brian Budge (brian.budge_at_[hidden])
Date: 2013-09-09 18:33:59


On Mon, Sep 9, 2013 at 2:35 PM, firespot71 <thomasmang.ng_at_[hidden]> wrote:

>
> But am I correct that both variants are safe, so neither deadlocks nor races
> may occur under any circumstances (ignore any issues outside of the code
> snippet above)?
> Once the notify-signal is issued each waiting thread needs to acquire the
> lock, and hence they get the lock strictly sequentially. I.e. most of them
> have to wait anyway while some other thread has the mutex locked. Variant 1
> has the advantage of 'bundling' the continuation and notification signal,
> and it also notifies other threads at the earliest possible point - of
> course given if it's technically allowed to do it while still locking the
> mutex, which I think is ok but not 100% sure.
>
> Thomas
>

Both variants are safe, but normal usage would say that variant 2 is
at least as efficient as variant 1. By normal usage I mean that
whichever thread is notified will need to acquire the lock before it
can do anything useful.

  Brian


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