Boost logo

Boost :

From: William Kempf (williamkempf_at_[hidden])
Date: 2001-09-06 15:45:59


From: dmoore_at_[hidden]
>A review from a Windows-centric programmer:
>
>1. Great, great, overall library
>2. In call_once, the line:
>
>swprintf(name, L"2AC1A572DB6944B0A65C38C4140AF2F4%X%X",
>GetCurrentProcessId(), &flag);
>
>Shouldn't you just generate a UUID for your unique naming prefix?

This would work, but wouldn't be as efficient since the same actual mutex
would be used for all calls to call_once... even those from seperate
programs. Adding the GetCurrentProcessId() reduces the granularity to all
calls to call_once within the process, while adding the address of &flag
reduces it to just the boost::once_flag instance.

>3. In many places in the code where there are resource allocation
>problems, you attempt to do cleanup by calling CloseHandle() before
>throwing the thread_resource_error() exeception (see condition::condition
>in particular). Calling CloseHandle(NULL) causes a Windows exception
>(C0000008) to be thrown, which will occur before you get your chance to
>throw thread_resource_error().

OK, I was unaware of the exception in this case. I'll fix the code.
Thanks.

>4. In semaphore::up(), I hadn't seen the idiom of "!!" before.
>
> bool ret = !!ReleaseSemaphore(reinterpret_cast<HANDLE>(m_sema),
count, &p);
>
>At first glance, I thought this was a bug (it's not), but it seems a bit
>odd. Would a cast from BOOL to bool or a comment be more clear?

It's a fairly common idiom (given the name "bang bang") that I expect many
(most?) people to be aware of. The cast may be more appropriate, it's just
a pain to code, and a comment would be even worse yet. I'm not sure what
others think about this idiom.

Bill Kempf

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp


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