Boost logo

Boost :

From: dmoore_at_[hidden]
Date: 2001-09-17 13:17:57


Previous discussions on ReleaseSemaphore....

> >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.
>
> I'm not sure I buy this explanation. Even though it's quite
possible that
> the return codes may be different between the platforms this simply
does not
> explain this situation. There's no "invalid parameter" being used
here.

You're right that there is no invalid parameter, but you're making
the mistake of applying logical reasoning to the win32 implementation
embodied in Windows 95 and Windows 98 (and Windows Me, too). It is a
low quality implementation, period. There is no respect for
consistency on these kinds of issues from MS. I'm actually a big
Win2k fan, but groan every time I have to do a "cross-platform"
development project for the 9x cousins.

This is just flat-out the way it is with 95/98. I'm including the
sample program I used to verify the behavior.

The following sample program:

int main(int argc, char* argv[])
{
        HANDLE hSem = CreateSemaphore(NULL,0,5,NULL);
        DWORD dret;

        if(hSem == NULL)
        {
                dret = GetLastError();
                std::cout << "Can't create semaphore ERRCODE:" <<
dret << std::endl;
                return -1;
        }

        for(int i = 0; i < 7; i++)
        {
                LONG count;
                BOOL ret = ReleaseSemaphore(hSem,1,&count);
                if(ret)
                {
                        std::cout << "Release Semphore #" << i << "
Prev Count " << count << std::endl;
                }
                else
                {
                        dret = GetLastError();
                        std::cout << "Can't release semaphore
ERRCODE:" << dret << std::endl;
                }
        }
        return 0;
}

When run on Win2k and Windows NT4.0 gives the following output:

Release Semphore #0 Prev Count 0
Release Semphore #1 Prev Count 1
Release Semphore #2 Prev Count 2
Release Semphore #3 Prev Count 3
Release Semphore #4 Prev Count 4
Can't release semaphore ERRCODE:298
Can't release semaphore ERRCODE:298

When run on Windows 98 (I didn't bother checking Windows 95), gives:

Release Semphore #0 Prev Count 0
Release Semphore #1 Prev Count 1
Release Semphore #2 Prev Count 2
Release Semphore #3 Prev Count 3
Release Semphore #4 Prev Count 4
Can't release semaphore ERRCODE:87
Can't release semaphore ERRCODE:87

Dave


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