Metered concurrency: Difference between revisions
Content deleted Content added
No edit summary |
No edit summary |
||
Line 6:
The interface for the counting semaphore is defined in an Ada package specification:
<
protected type Counting_Semaphore(Max : Positive) is
entry Acquire;
Line 14:
Lock_Count : Natural := 0;
end Counting_Semaphore;
end Semaphores;</
The ''Acquire'' entry has a condition associated with it. A task can only execute the ''Acquire'' entry when ''Lock_Count'' is less than ''Max''. This is the key to making this structure behave as a counting semaphore. This condition, and all the other aspects of ''Counting_Semaphore'' are contained in the package body.
<
------------------------
Line 55:
end Counting_Semaphore;
end Semaphores;</
We now need a set of tasks to properly call an instance of ''Counting_Semaphore''.
<
with Ada.Text_Io; use Ada.Text_Io;
|