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.         -- Takes the lock. The calling thread will block until the lock is free. 
  12.         -- This must not be called again by the caller until it calls Unlock. 
  13.         entry Lock( owner : Task_Id := Current_Task ); 
  14.  
  15.         -- Immediately releases the lock. Only the thread that has first called 
  16.         -- Lock should call Unlock. Raises LOCK_USE_EXCEPTION if the lock is 
  17.         -- being used illegally. 
  18.         procedure Unlock; 
  19.  
  20.     private 
  21.         lockingTask : Task_Id := Null_Task_Id; 
  22.     end Locking_Object; 
  23.  
  24.     type A_Locking_Object is access all Locking_Object; 
  25.  
  26.     procedure Delete is new Ada.Unchecked_Deallocation( Locking_Object, A_Locking_Object ); 
  27.  
  28.     LOCK_USE_EXCEPTION : exception; 
  29.  
  30. end Locking_Objects;