Got an iPhone or iPad? We have a brand new Pastebin App for both devices, and it's totally free! Click here to download the new Pastebin App for iOS.
Guest

Sam

By: a guest on Oct 27th, 2007  |  syntax: Ada  |  size: 0.91 KB  |  hits: 37  |  expires: Never
download  |  raw  |  embed  |  report abuse
This paste has a previous version, view the difference. Copied
  1. package P is
  2.  
  3.    Shared : Natural := 0;
  4.  
  5.    procedure Maybe_Increment;
  6.  
  7. end P;
  8.  
  9. package body P is
  10.  
  11.    protected Lock is
  12.       entry Maybe_Lock (Lock_Acquired : out Boolean);
  13.       entry Maybe_Unlock (Was_Locked : Boolean);
  14.    private
  15.       Is_Locked : Boolean := False;
  16.    end Lock;
  17.  
  18.    protected body Lock is
  19.  
  20.       entry Maybe_Lock (Lock_Acquired : out Boolean) when True is
  21.       begin
  22.          Lock_Acquired := not Is_Locked;
  23.          Is_Locked     := True;
  24.       end Maybe_Lock;
  25.  
  26.       entry Maybe_Unlock (Was_Locked : Boolean) when True is
  27.       begin
  28.          if Was_Locked then
  29.            Is_Locked := False;
  30.          end if;
  31.       end Maybe_Unlock;
  32.  
  33.    end Lock;
  34.  
  35.    procedure Maybe_Increment is
  36.       L : Boolean;
  37.    begin
  38.       Lock.Maybe_Lock (L);
  39.       if L then
  40.          Shared := Shared + 1;
  41.       end if;
  42.       Lock.Maybe_Unlock (L);
  43.    end Maybe_Increment;
  44.  
  45. end P;