Boost logo

Boost :

From: cop_at_[hidden]
Date: 2001-09-15 22:56:57


--- In boost_at_y..., dmoore_at_a... wrote:
> > --- In boost_at_y..., John Maddock <John_Maddock_at_c...> wrote:
> > >In Semaphore::up the assert:
> > >
> > > assert(ret || GetLastError() == ERROR_TOO_MANY_POSTS);
> > >
> > >is failing for the semaphore test in thread_test.cpp, it seems as
> > though
> > >GetLastError is returning ERROR_INVALID_PARAMETER rather than
> > >ERROR_TOO_MANY_POSTS on my Win98 box.
> >
> > I only have access to Win2K machines at this point, and I can not
> reproduce
> > this problem nor can I see a reason for it. I'd really
appreciate
> it if
> > anyone can explain why this is occuring.
>
> This is unfortunately one of the many quirks of using the "same"
> Win32 API on two fundamentally different OS kernels (98 vs 2k).
Wait
> until you see the differences in the virtual memory systems if you
> ever tackle a Boost Memory Map class!
>
> The MSDN docs are silent on the possible error codes returned by
> ReleaseSemaphore, actually, but differences in return codes do
exist
> throughout the synchronization and VM apis.
>
> Dave

Since GetLastError() might report different errors on different Win32
platforms, the only safe assumption is probably assert(GetLastError
() != ERROR_SUCCESS).

Also note that calling GetLastError() in DEBUG only code is dangerous
because GetLastError() is NOT side-effect free! I tracked down a bug
at work where the following code was mysteriously failing in debug
builds:

    assert(GetLastError() == ERROR_SUCCESS); // no errors
    if (GetLastError() != ERROR_SUCCESS) // mysterious error appears?!

The first call to GetLastError() in the assert() apparently cleared
the thread's error code, so the second call to GetLastError() in the
non-debug code returned a garbage value! I was very surprised. I
fixed the problem like this:

    DWORD error = GetLastError();
    assert(ERROR_SUCCESS == error);
    if (ERROR_SUCCESS != error) ...

Chris


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