Boost logo

Boost :

From: David Abrahams (david.abrahams_at_[hidden])
Date: 2002-01-19 14:31:50


----- Original Message -----
From: "bill_kempf" <williamkempf_at_[hidden]>

> Yes, plausible, but I don't see how this scenario requires a heap
> based approach.
>
> void operation()
> {
> // initial stuff
> {
> disable_cancellation protect;
> // loop
> }
> // other stuff
> }
>
> Can you illustrate what you were thinking in code?

I was thinking of something more like this. The idea is to avoid throwing
exceptions once we start modifying the resource:

// use this with std::accumulate
struct operator
{
    template <class T>
    int operator()(T& x, int checksum) const
    {
        wait_for_condition(x.cv()); // might cancel

        if (satisfies_some_condition(x))
        {
            if (disable_cancellation.get() == 0)
            {
                // about to start modifying. Now we'd better not throw
                m_protector.reset(new disable_cancellation);
            }
            modify(x);
        }
        // Haven't started modifying sequence; OK to cancel
        checksum += crc(x);
        return checksum;
    }

    std::auto_ptr<wait_for_condition> m_protector;
};


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