🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.os2.programmer
Article #168

Semaphores doesn't work with queues

#168
From: Jaakko J Salmenius
Date: Wed, 04 Nov 1992 15:28
69 lines
3039 bytes
Hi there,

I have a problem considering about OS/2 1.2 queues.

My idea is to implement a C++ class Queue whose Peek member function takes
a parameter that indicates how long the functions should wait for a item to
come into the queue.

DosPeekQueue doesn't support this directly but it gives the user a choice
between immediate return or waiting for a item to come. There is no
wait-until-come-or-time-counts-up.

The last parameter in DosPeekQueue function is a handle to the system semaphore
or a address to the RAM semaphore. I desided to use that. I'm using RAM
semaphores. My idea is first to call DosPeekQueue with no wait option so the
functions will return right away in any case (there is a item or there is not).
If the result code indicated that the queue was empty then the function
waits for the semaphore to clear. This should happen every time a item enters
into the queue.

This is my code:


ULONG Queue::Peek(
        ...

        ULONG semaphore = 0;

        result = DosPeekQueue(
                handle,
                &resultStruct,
                &messageSize,
                (PULONG)&message,
                &messageId,
                DCWW_NOWAIT,
                &tempPriority,
                (ULONG)&semaphore);
        if ((result == ERROR_QUE_ELEMENT_NOT_EXIST) ||
                (result == ERROR_QUE_EMPTY))
        {
                DosSemWait(&semaphore, timeOut);
                result = DosPeekQueue(
                        handle,
                        &resultStruct,
                        &messageSize,
                        (PULONG)&message,
                        &messageId,
                        DCWW_NOWAIT,
                        &tempPriority,
                        (ULONG)0);
        }

        ...

The problem is that OS/2 doesn't clear the semaphore even if there is a item
in the queue. So, what my program does is that it waits for the period of
timeOut and DosSemWait returns ERROR_SEM_TIMEOUT.

Is this the right way to use semaphores with queues?
QuickHelp and printed documents doesn't tell much about the matter.

I hope that Microsoft gives better documents with NT.
                

                Jaakko
--
Jaakko Salmenius	| Helsinki University of Technology
salmeniu@niksula.hut.fi	| The believable ski heroes, at least in my opinion,
tel +358-0-805 5951	| are the ones who ski the extreme.
Technical Details
Message-ID: <1992Nov4.152838.2341@nntp.hut.fi>
Path: arc1-ca.pugleaf.net!sparky!uunet!pipex!unipalm!uknet!mcsun!news.funet.fi!funic!nntp.hut.fi!robocop.cs.hut.fi!salmeniu
References: <1992Aug12.184126.20420@jupiter.sun.csd.unb.ca>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!pipex!unipalm!uknet!mcsun!news.funet.fi!funic!nntp.hut.fi!robocop.cs.hut.fi!salmeniu
From: salmeniu@robocop.cs.hut.fi (Jaakko J Salmenius)
Newsgroups: comp.os.os2.programmer
Subject: Semaphores doesn't work with queues
Message-ID: <1992Nov4.152838.2341@nntp.hut.fi>
Date: 4 Nov 92 15:28:38 GMT
References: <1992Aug12.184126.20420@jupiter.sun.csd.unb.ca>
Sender: usenet@nntp.hut.fi (Usenet pseudouser id)
Reply-To: salmeniu@niksula.hut.fi (Jaakko J Salmenius)
Organization: Helsinki University of Technology, Finland
Lines: 69
Nntp-Posting-Host: robocop.cs.hut.fi