Boost logo

Boost :

From: Alexander Terekhov (terekhov_at_[hidden])
Date: 2004-07-20 14:32:02


Alexander Terekhov wrote:
>
> Peter Dimov wrote:
> [...]
> > > I have PS/2 Model 80 (with 64 Megs) "tank" at home (in addition to
> > > A31p ThinkPad ;-) ).
> >
> > He he. OK, if you had CAS (PS/2 Model 70 486) how would you do it?
>
> Ok, you owe me a "Blue Lightening" processor upgrade. ;-) How about
>
> void lock() throw() {
> while (int lock_status = m_lock_status.cas(0, 1, msync::ddacq))
> if (lock_status < 0 || m_lock_status.cas(1,-1, msync::ddacq))
> m_retry_event.wait();

Err. m_retry_event.wait(), m_retry_event.set();

> }
>
> bool trylock() throw() {
> return !m_lock_status.cas(0, 1, msync::acq);
> }
>
> bool timedlock(absolute_timeout const & timeout) throw() {
> while (int lock_status = m_lock_status.cas(0, 1, msync::ddacq))
> if (lock_status < 0 || m_lock_status.cas(1,-1, msync::ddacq))
> if (!m_retry_event.timedwait(timeout)) m_retry_event.set(),
> return !m_lock_status.swap(1, msync::acq);
> return true;
> }

Forget it. timedlock() would make it "posix unsafe". lock_queue is
the way to go.

regards,
alexander.


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