Boost logo

Boost :

Subject: Re: [boost] boost interprocess (>1.45) robust mutexes
From: Kim Barrett (kab.conundrums_at_[hidden])
Date: 2011-03-31 19:04:16


On Mar 31, 2011, at 4:30 PM, Ion Gaztañaga wrote:
> El 31/03/2011 21:04, Kim Barrett escribió:
>> On Mar 31, 2011, at 2:41 PM, Kim Barrett wrote:
>>> I developed an API for robust mutexes and associated condition
>>> variables that has been in use for a while by my employer.
>
> Thanks for the ideas. That would require adding a handler function to lock types, right? How does this work with a typical condition variable wait loop? Shouldn't we notify the result to the caller?

Yes, the lock type associated with robust mutexes also needs to have
its locking and constructor functions take a handler function.

The caller provides the handler function.

So one has something like

class robust_mutex {
public:
    ... constructors & etc ...

    template<class Handler>
    void lock(Handler handler);

    void unlock();

    void set_consistent();
    void set_unrecoverable();
};

class robust_lock {
public:
    // lock mutex
    template<class Handler>
    robust_lock(robust_mutex& mutex, Handler handler);
    // unlock mutex
    ~robust_lock();

    template<class Handler>
    void lock(Handler handler);

    void unlock();
    robust_mutex& get_mutex();
};

class robust_condition {
public:
    ... constructors & etc ...

    template<class Lock, class Handler>
    wait(Lock& lock, Handler handler);

    template<class Lock, class Handler>
    bool timed_wait(Lock& lock, <timetype> timeout, Handler handler);

    void notify_one();
    void notify_all();
};

where in all cases the handler is called with an argument which is a
reference to the mutex when the locking operation on the mutex
returned EOWNERDEAD. The handler is called with the mutex locked.


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