home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!vnet.ibm.com
- From: peterf@vnet.ibm.com (Peter Forsberg)
- Message-ID: <19921104.224427.70@almaden.ibm.com>
- Date: Thu, 5 Nov 92 07:39:05 SWE
- Newsgroups: comp.os.os2.programmer
- Subject: Re: Semaphores doesn't work with queues
- Reply-To: peterf@vnet.ibm.com
- Organization: IBM Corporation
- Disclaimer: This posting represents the poster's views, not those of IBM
- News-Software: UReply 3.0
- References: <1992Aug12.184126.20420@jupiter.sun.csd.unb.ca>
- <1992Nov4.152838.2341@nntp.hut.fi>
- Lines: 81
-
- In <1992Nov4.152838.2341@nntp.hut.fi> Jaakko J Salmenius writes:
- >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.
- >
-
- It doesn't look like you set the semaphore. Do you do that in the real
- code? You should call DosSemSet before the first DosPeekQueue.
-
- This queue-semaphore business is a bit tricky, and the docs have always been
- a bit obscure about it.
-
- Peter
- --
- Peter Forsberg E-mail: peterf@vnet.ibm.com (primary)
- d88-pfo@nada.kth.se (alternate)
- Disclaimer: This posting represents the poster's views, not those of IBM
-