|
Boost : |
From: Peter Dimov (pdimov_at_[hidden])
Date: 2006-11-01 12:23:52
Roland Schwarz wrote:
> Peter Dimov wrote:
>> No, lk is explicitly documented as being not thread safe. When two
>> threads attempt to lock lk at the same time, the behavior is
>> undefined.
>
> Yes I know this, and I also explicitly stated it.
Indeed, sorry for not paying attention. But the only point of locking a
mutex is to be able to do that from two different threads at the same time.
If you know that only one thread is accessing the scoped_lock at a time, you
wouldn't need a scoped_lock in the first place.
> But on the other hand: A mutex must not be locked from
> one thread and unlocked from another too. True?
True.
> So this (unscoped) usage is dangerous in any case, isn't it?
True. The recommended way to lock a mutex is still via the scoped_lock. The
direct interface is provided because when it's needed, there is no safer way
to get it. Sometimes you just need to lock the mutex in one place and unlock
it in another, and there is no way around it.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk