1. with Ada.Task_Identification;           use Ada.Task_Identification; 
  2. with Ada.Unchecked_Deallocation; 
  3.  
  4. package Locking_Objects is 
  5.  
  6.     pragma Preelaborate; 
  7.  
  8.     -- A simple protected object used to implement a lock mutex. 
  9.     protected type Locking_Object is 
  10.  
  11.         -- Call this to take the lock. The calling thread will block until the 
  12.         -- lock is free. This may not be called again by the caller until it 
  13.         -- calls Unlock. 
  14.         entry Lock( owner : Task_Id := Current_Task ); 
  15.  
  16.         -- Call this to immediately release the lock. Only a thread which has 
  17.         -- called Lock should call Unlock. Raises LOCK_USE_EXCEPTION if the lock 
  18.         -- is being used illegally. 
  19.         procedure Unlock; 
  20.  
  21.     private 
  22.         lockingTask : Task_Id := Null_Task_Id; 
  23.     end Locking_Object; 
  24.  
  25.     type A_Locking_Object is access all Locking_Object; 
  26.  
  27.     procedure Delete is new Ada.Unchecked_Deallocation( Locking_Object, A_Locking_Object ); 
  28.  
  29.     LOCK_USE_EXCEPTION : exception; 
  30.  
  31. end Locking_Objects;