[sv-bc] Semaphore question

From: LaFlamme, Jamie <jamiel_at_.....>
Date: Wed Sep 14 2005 - 14:09:05 PDT
The LRM description for semaphore::get() includes the following two
statements:
 
    (1) If the specified number of keys are available, the method
returns and execution continues.
    (2) The semaphore waiting queue is First-In First-Out (FIFO).

If I'm interpreting (1) and (2) correctly, then the behavior would be
somewhat inconsistent when handling requests for different numbers of
keys.  My interpretation is that in this example:

    semaphore c = new(1);
    initial c.get(2);    // process 1 blocks
    initial #1 c.get(1); // process 2 executes without blocking
    initial #2 c.put(2); // causes process 2 to execute

the request for 1 key will be satisfied before the request for 2 keys
because the get(1) never gets put on the waiting queue.  On the other
hand, in this example:

    semaphore c = new(0);
    initial c.get(2);     // process 1 blocks
    initial #1 c.get(1);  // process 2 blocks
    initial #2 c.put(1);  // neither process 1 or process 2 resumes

process 2 never unblocks because process 1 is first in the waiting queue
and the queue must maintain FIFO ordering.  This seems somewhat
inconsistent - am I misinterpreting the LRM or does the LRM need to be
clarified?

Thanks,
-Jamie
Received on Wed Sep 14 14:09:25 2005

This archive was generated by hypermail 2.1.8 : Wed Sep 14 2005 - 14:12:19 PDT