Boost logo

Boost :

From: Bill Wade (bill.wade_at_[hidden])
Date: 2000-09-08 14:36:39


> From: William Kempf [mailto:sirwillard_at_[hidden]]

> Interesting trick. A question though... if we have this code:
>
> {
> mutex mx;
> unsafe_lock<mutex> lock(mx);
> lock.unlock();
> }
>
> won't the m_lock.~basic_lock<M>() be called multiple times? That's
> why I used an array to begin with.

You are correct. Never mind.

> > Mostly unrelated question:
> >
> > Have you got a way to atomically convert a non-recursive
> > MutexTryLock::try_lock into a MutexLock::lock that can be used with
> a cv?
> > How do I get non-blocking access to a cv (and its associated mutex)?
>
> I don't follow the question here, sorry. Could you re-ask and
> possibly post pseudo-code illustrating it?

Using the buffer class from ConditionVariable.html. Suppose I want to write
a non-blocking buffer::receive(). I know you're thinking about adding a
timeout to wait(), but before I can even call wait() you want me to have a
lock.

If the mutex is recursive I could use

  M::try_lock tlk(mutex);
  if(tlk)
  {
    M::lock lk(mutex);
    wait(lk, ...);
    DoSomethingInteresting();
  }

I was wondering if you had a workable solution for the case where the mutex
is non-recursive. In other words I'm suggesting that there be a conversion
from try_lock to lock (of course the conversion is allowed to fail).


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