Thread View: comp.os.os2.programmer
5 messages
5 total messages
Started by Anthony Thomas Green
Fri, 26 Oct 1990 20:38
Counting semaphores?
Author: Anthony Thomas Green
Date: Fri, 26 Oct 1990 20:38
Date: Fri, 26 Oct 1990 20:38
10 lines
662 bytes
662 bytes
I have a question regarding the use of semaphores. Is it possible to set up a system semaphore that must be cleared as many times as it has been set in order for a waiting thread to become runnable? ATdhvaannkcse Anthony Green green@ai.toronto.edu
Re: Counting semaphores?
Author: lsalomo
Date: Mon, 29 Oct 1990 14:39
Date: Mon, 29 Oct 1990 14:39
16 lines
1105 bytes
1105 bytes
From article <90Oct26.163804edt.8236@orasis.vis.toronto.edu>, by green@vis.toronto.edu (Anthony Thomas Green): > Is it possible to set up a system semaphore that must be cleared as many > times as it has been set in order for a waiting thread to become > runnable? I always thought that's the way RAM semaphores were implemented? Cheers, Q - the "Q"uestor for knowledge (, a degree, etc.) lsalomo@hubcap.clemson.edu ibmman@prism.clemson.edu ibmman@clemson.clemson.edu ============================================================================= "Gee Wally, I think there's something wrong with the Beaver." =============================================================================
Re: Counting semaphores?
Author: Bob Niedergerke
Date: Mon, 29 Oct 1990 22:08
Date: Mon, 29 Oct 1990 22:08
12 lines
1102 bytes
1102 bytes
In article <11219@hubcap.clemson.edu> lsalomo@hubcap.clemson.edu (lsalomo) writes: >From article <90Oct26.163804edt.8236@orasis.vis.toronto.edu>, by green@vis.toronto.edu (Anthony Thomas Green): >> Is it possible to set up a system semaphore that must be cleared as many >> times as it has been set in order for a waiting thread to become runnable? > >I always thought that's the way RAM semaphores were implemented? It all depends. If you use DosSemRequest and DosSemClear, the behavior is as described above. Using a DosSemWait/DosSemClear scheme, the semaphore need only be cleared once for a waiting thread to become runnable. bobn
Re: Counting semaphores?
Author: Tom Johnson
Date: Wed, 31 Oct 1990 22:46
Date: Wed, 31 Oct 1990 22:46
50 lines
2407 bytes
2407 bytes
>>> Is it possible to set up a system semaphore that must be cleared as many
>> times as it has been set in order for a waiting thread to become runnable?
>
>>I always thought that's the way RAM semaphores were implemented?
> It all depends. If you use DosSemRequest and DosSemClear, the behavior is
> as described above. Using a DosSemWait/DosSemClear scheme, the semaphore
> need only be cleared once for a waiting thread to become runnable.
> ----------
I'm not so sure this is true, but I can't say I've ever tried it.
According to the Programmers Reference, "The DosSemRequest function requests
that the specified semaphore be set AS SOON AS IT IS CLEAR...If the
semaphore has already been set by another thread, the function WAITS until
a thread clears the semaphore... or until a time-out occurs."
It sounds to me like this is not what is desired by the original poster.
What is needed is a way to set a semaphore without waiting, but have the
semaphore not be cleared until all threads that set the semaphore clear
it. I'm not sure DosSemRequest can do that.
If OS/2 doesn't give you this functionality, it is possible to create
this functionality using 2 normal system semaphores. The following
algorithm describes how to do it:
var MUTEX, DELAY: SEMAPHORE /* binary semaphores */
K: INTEGER; /* counting semaphore value */
MUTEX = 1; DELAY = 0;
K = x; /* initialize it to highest desired value */
P(K) = P(MUTEX);
K = K - 1;
if K < 0 then
V(MUTEX);
P(DELAY);
else
V(MUTEX);
V(K) = P(MUTEX);
K = K + 1;
if K <= 0
V(DELAY);
V(MUTEX);
If this isn't clear, sorry, but I didn't have time to study it. I
got the algorithm from "Parallel Programming" by R.H. Perrott. Almost
any decent Operating Systems book should have a similar algorithm.
Tom Johnson
Re: Counting semaphores?
Author: Dan SPALDING
Date: Sat, 03 Nov 1990 20:05
Date: Sat, 03 Nov 1990 20:05
12 lines
1103 bytes
1103 bytes
In article <1610001@hpcc01.HP.COM> tomj@hpcc01.HP.COM (Tom Johnson) writes: >>>> Is it possible to set up a system semaphore that must be cleared as many >>> times as it has been set in order for a waiting thread to become >runnable? >> >>>I always thought that's the way RAM semaphores were implemented? > What you want to use is the Fast Safe Ram semaphores or named (system) semaphores. Both of them will implement counting and won't release some thread waiting on the semaphore until the count reaches zero. However, the same process can request the semaphore if it already owns it (in the same thread) and it just bumps the count.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads