anchor.diff:    ets:insert_new(?MODULE, [{Key, Pid} || Key <- Keys]).
         
   should_lock_more(Keys, Pid) ->
  -  lists:foldl( fun(_Key, {false, _KeysToTry}) ->
  -                   {false, []};
  -                  (Key, {true, KeysToTry}) ->
  -                   case ets:lookup(?MODULE, Key) of
  +  lists:foldl(fun(_Key, {false, _KeysToTry}) ->
  +                  {false, []};
  +                 (Key, {true, KeysToTry}) ->
  +                  case ets:lookup(?MODULE, Key) of
                       [] ->
  -                       {true, [Key|KeysToTry]};
  -                     {Key, Pid} ->
  -                       {true, KeysToTry};
  -                     {Key, _OtherPid} ->
  -                       {false, []}
  -                   end
  -               end
  +                      {true, [Key|KeysToTry]};
  +                    [{Key, Pid}] ->
  +                      {true, KeysToTry};
  +                    [{Key, _OtherPid}] ->
  +                      {false, []}
  +                  end
  +              end
                , {true, []}
                , Keys).
  -                       
  +
   release_lock_int(Keys) ->
     lists:foreach( fun(Key) ->
                        ets:delete(?MODULE, Key)
  
positive.code: 
  handle_cast({release_lock, ReleaseKeys, Pid},  #s{monitors = M0} = S) ->
    M = case lists:keyfind(Pid, 1, M0) of
          {Pid, {Ref, LockedKeys}} when ReleaseKeys == LockedKeys ->
            erlang:demonitor(Ref),
            release_lock_int(ReleaseKeys),
            lists:keydelete(Pid, 1, M0);
          {Pid, {Ref, LockedKeys0}} ->
            release_lock_int(ReleaseKeys),
            LockedKeys = subtract_sorted_keys(ReleaseKeys, LockedKeys0),
            lists:keyreplace(Pid, 1, M0, {Pid, {Ref, LockedKeys}});
          false ->
            M0
        end,
    {no_reply, S#s{monitors = M}};
  handle_cast(_, S) ->
    {no_reply, S}.
  
  handle_info({'DOWN', _Ref, process, Pid, _Info}, #s{monitors = M0} = S) ->
    M = case lists:keyfind(Pid, 1, M0) of
  
negative.code: 
  subtract_sorted_keys([R0|Rs], [R0|Ls], Acc) ->
    subtract_sorted_keys(Rs, Ls, Acc);
  subtract_sorted_keys([R0|Rs], [L0|Ls], Acc) when R0 < L0 ->
    subtract_sorted_keys(Rs, [L0|Ls], Acc);
  subtract_sorted_keys([R0|Rs], [L0|Ls], Acc) ->
    subtract_sorted_keys([R0|Rs], Ls, [L0|Acc]);
  subtract_sorted_keys(_Rs, [], Acc) ->
    lists:reverse(Acc);
  subtract_sorted_keys([], Ls, Acc) ->
    lists:reverse(Acc) ++ Ls.
  
  tick_period() ->
    %% In milliseconds.
  