Boost logo

Boost :

From: Anthony Williams (anthony_w.geo_at_[hidden])
Date: 2005-09-04 16:28:54


"Peter Dimov" <pdimov_at_[hidden]> writes:

> Anthony Williams wrote:
>> Also, the semaphore version runs the function once, even if it
>> throws an exception. The mutex version runs the function repeatedly
>> if it throws an exception. The docs say that the function isn't
>> allowed to throw, so this is a moot point.
>
> I like the signature of call_once:
>
> template<typename Function>
> void call_once(Function f, once_flag& flag)
>
> but you need to fix the above behavior. The function is considered "run"
> only when it returns without an exception. So your semaphore version runs it
> zero times when an exception is thrown.

void f()
{
    throw "something";
}

int main()
{
    try
    {
        f();
    }
    catch(...){}
}

How many times has f() been *called*? One, or none? I find your concept of a
function only having run if it exits without an exception odd.

In my mind call_once means just that --- call the function once, not let it
run without an exception once. The docs
(http://www.boost.org/regression-logs/cs-win32_metacomm/doc/html/call_once.html)
say that "the function func shall not
throw exceptions", so handling it this way is certainly acceptable, IMO.

Anthony

-- 
Anthony Williams
Software Developer

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