[comp.os.os2.programmer] Counting SEMs in OS/2?!?

kushner@ux5.lbl.gov (Gary Kushner) (11/22/90)

Does anyone know if there are counting semaphores in OS/2 version
1.2??  I have a resource that can have multiple users, I want to
use a counting semaphore to control access.  I would like to be
able to DosSemClear() the semaphore N times, and then other
processes could DosSemRequest() the semaphore that number of times
without being blocked.

Can this be done?  (There should be an <easy> way!)
I would be very appreciative if someone could post or send me
the answer!

Thanks,
-Gary

fealon@nadia.stgt.sub.org (Frank Fuchs) (11/27/90)

In article <8201@dog.ee.lbl.gov> kushner@ux5.lbl.gov (Gary Kushner) writes:
>Does anyone know if there are counting semaphores in OS/2 version
>1.2??  I have a resource that can have multiple users, I want to
>use a counting semaphore to control access.  I would like to be
>able to DosSemClear() the semaphore N times, and then other
>processes could DosSemRequest() the semaphore that number of times
>without being blocked.
>

private system semaphores (DosCreateSem with parameter CSEM_PRIVATE) have to be
cleared as many times as they have been set. The reason for this was that you
should be able to write recursive functions that request ownership of a
resource in each recursion level and free the resource every time they 'return'.

Bye,
-- 
Fealon, a.k.a. Frank Fuchs (Foxware), fealon@nadia.stgt.sub.org

kushner@ux1.lbl.gov (Gary Kushner) (12/02/90)

>private system semaphores (DosCreateSem with parameter CSEM_PRIVATE) have to be
>cleared as many times as they have been set. The reason for this was that you
>should be able to write recursive functions that request ownership of a
>resource in each recursion level and free the resource every time they 'return'.

Actually what I meant was more like the traditional P and V
operations.  I wanted to be able to initialize a SEM to a count
and then have threads be able to P (request) the sem as many
times as the original count.  Used for controlling resources
that can have more than one and less than all users.

It turned out the code to implement counting semaphores in OS/2
was quite trivial.  It is just to bad that Microsoft didn't
include them in the first place.

-Gary