home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / os / os2 / programm / 6211 next >
Encoding:
Internet Message Format  |  1992-11-04  |  3.4 KB

  1. Path: sparky!uunet!vnet.ibm.com
  2. From: peterf@vnet.ibm.com (Peter Forsberg)
  3. Message-ID: <19921104.224427.70@almaden.ibm.com>
  4. Date: Thu, 5 Nov 92 07:39:05 SWE
  5. Newsgroups: comp.os.os2.programmer
  6. Subject: Re: Semaphores doesn't work with queues
  7. Reply-To: peterf@vnet.ibm.com
  8. Organization: IBM Corporation
  9. Disclaimer: This posting represents the poster's views, not those of IBM
  10. News-Software: UReply 3.0
  11. References: <1992Aug12.184126.20420@jupiter.sun.csd.unb.ca>
  12.             <1992Nov4.152838.2341@nntp.hut.fi>
  13. Lines: 81
  14.  
  15. In <1992Nov4.152838.2341@nntp.hut.fi> Jaakko J Salmenius writes:
  16. >Hi there,
  17. >
  18. >I have a problem considering about OS/2 1.2 queues.
  19. >
  20. >My idea is to implement a C++ class Queue whose Peek member function takes
  21. >a parameter that indicates how long the functions should wait for a item to
  22. >come into the queue.
  23. >
  24. >DosPeekQueue doesn't support this directly but it gives the user a choice
  25. >between immediate return or waiting for a item to come. There is no
  26. >wait-until-come-or-time-counts-up.
  27. >
  28. >The last parameter in DosPeekQueue function is a handle to the system semaphore
  29. >or a address to the RAM semaphore. I desided to use that. I'm using RAM
  30. >semaphores. My idea is first to call DosPeekQueue with no wait option so the
  31. >functions will return right away in any case (there is a item or there is not).
  32. >If the result code indicated that the queue was empty then the function
  33. >waits for the semaphore to clear. This should happen every time a item enters
  34. >into the queue.
  35. >
  36. >This is my code:
  37. >
  38. >ULONG Queue::Peek(
  39. >        ...
  40. >
  41. >        ULONG semaphore = 0;
  42. >
  43. >        result = DosPeekQueue(
  44. >                handle,
  45. >                &resultStruct,
  46. >                &messageSize,
  47. >                (PULONG)&message,
  48. >                &messageId,
  49. >                DCWW_NOWAIT,
  50. >                &tempPriority,
  51. >                (ULONG)&semaphore);
  52. >        if ((result == ERROR_QUE_ELEMENT_NOT_EXIST) ||
  53. >                (result == ERROR_QUE_EMPTY))
  54. >        {
  55. >                DosSemWait(&semaphore, timeOut);
  56. >                result = DosPeekQueue(
  57. >                        handle,
  58. >                        &resultStruct,
  59. >                        &messageSize,
  60. >                        (PULONG)&message,
  61. >                        &messageId,
  62. >                        DCWW_NOWAIT,
  63. >                        &tempPriority,
  64. >                        (ULONG)0);
  65. >        }
  66. >
  67. >        ...
  68. >
  69. >The problem is that OS/2 doesn't clear the semaphore even if there is a item
  70. >in the queue. So, what my program does is that it waits for the period of
  71. >timeOut and DosSemWait returns ERROR_SEM_TIMEOUT.
  72. >
  73. >Is this the right way to use semaphores with queues?
  74. >QuickHelp and printed documents doesn't tell much about the matter.
  75. >
  76. >I hope that Microsoft gives better documents with NT.
  77. >
  78. >                Jaakko
  79. >--
  80. >Jaakko Salmenius  | Helsinki University of Technology
  81. >salmeniu@niksula.hut.fi     | The believable ski heroes, at least in my opinion,
  82. >tel +358-0-805 5951    | are the ones who ski the extreme.
  83. >
  84.  
  85. It doesn't look like you set the semaphore. Do you do that in the real
  86. code? You should call DosSemSet before the first DosPeekQueue.
  87.  
  88. This queue-semaphore business is a bit tricky, and the docs have always been
  89. a bit obscure about it.
  90.  
  91. Peter
  92. --
  93. Peter Forsberg           E-mail:  peterf@vnet.ibm.com          (primary)
  94.                                   d88-pfo@nada.kth.se        (alternate)
  95. Disclaimer: This posting represents the poster's views, not those of IBM
  96.