Boost logo

Boost :

From: Howard Hinnant (hinnant_at_[hidden])
Date: 2007-03-26 15:14:45


On Mar 26, 2007, at 2:47 PM, Peter Dimov wrote:

> But my question is more along the lines of: why does the const/non-
> const
> label matter when we decide on the precondition and thread safety of
> t.cancel? If t.cancel is always valid on a valid t, this makes sharing
> possible and safe, regardless of whether thread::cancel is declared
> const.

I guess my answer would go back to this snippet:

void foo(const thread& t);

void bar()
{
     std::thread t(f);
     ...
     foo(t);
     ...
}

Because of the const qualifier on the thread& which foo takes as a
parameter, and knowing that the const interface of thread is a subset
of the non-const interface, we can make useful assumptions about t
after the call to foo() (such as t hasn't been canceled). This might
be particularly helpful if foo is a virtual function.

-Howard


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