|
Boost : |
From: Anthony Williams (anthony_w.geo_at_[hidden])
Date: 2005-09-02 01:26:14
Matt Hurd <matt.hurd_at_[hidden]> writes:
>> On 02/09/05, Anthony Williams <anthony_w.geo_at_[hidden]> wrote:
>
>> > Any volunteers for specific platforms? No need for just one per platform.
>>
>> I'm happy to work with Roland on the win32 port; I've looked at lots of the
>> issues relating to thread primitives on Windows before.
>
> Super!
Right-oh. Here's two implementations of call_once (attached), for starters.
once.hpp uses a Semaphore, whereas once_mutex.hpp uses a mutex, the same as
the existing boost::thread implementation.
Running the test program, the semaphore version gives a timing of 16s compiled
with gcc-mingw-4.0.1, and 22s compiled with MSVC 7.1, on my machine. The mutex
version gives timings of 23s (gcc) and 29s (MSVC), so the semaphore version is
clearly faster.
The mutex version allows for comparison of the once_flag instance against
BOOST_ONCE_INIT, as implicitly suggested by the docs, whereas the semaphore
version doesn't allow this, as BOOST_ONCE_INIT is an aggregate initializer.
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'd rather go with the semaphore version, but if others prefer the mutex
version, I'll go with that.
Both versions would need touching-up to handle wide-char-only platforms
(winCE?), and platforms without stringstream.
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