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:
<Adalang ada> package Semaphores is
protected type Counting_Semaphore(Max : Positive) is
entry Acquire;
Line 14:
Lock_Count : Natural := 0;
end Counting_Semaphore;
end Semaphores;</Adalang>
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.
<Adalang ada> package body Semaphores is
------------------------
Line 55:
end Counting_Semaphore;
end Semaphores;</Adalang>
We now need a set of tasks to properly call an instance of ''Counting_Semaphore''.
<Adalang ada> with Semaphores;
with Ada.Text_Io; use Ada.Text_Io;