anchor.diff:      %% would have happened if we actually hibernated
       %% and immediately was awakened
       Hibernate andalso garbage_collect(),
  +    %% So now the old Hibernate is dead, and a new one emerges
  +    %% within loop_event_actions
       case call_state_function(S, Type, Content, State, Data) of
   	{ok,Result,NewS} ->
   	    %% Cancel event timeout
  -	    {NewTimerRefs,NewTimerTypes} =
  -		cancel_timer_by_type(timeout, TimerRefs, TimerTypes),
  +	    {NewTimerTypes,NewCancelTimers} =
  +		cancel_timer_by_type(timeout, TimerTypes, CancelTimers),
  +	    %% The timer is removed from NewTimerTypes but
  +	    %% remains in TimerRefs until we get the cancel_timers msg
   	    {NewData,NextState,Actions,EnterCall} =
   		parse_event_result(
  -		  true, Debug, NewS, NewTimerRefs, NewTimerTypes,
  -		  Events, Event, State, Data, Hibernate, Result),
  +		  true, Debug, NewS,
  +		  TimerRefs, NewTimerTypes, NewCancelTimers,
  +		  Events, Event, State, Data, false, Result),
   	    loop_event_actions(
  -	      Parent, Debug, NewS, TimerRefs, NewTimerTypes,
  +	      Parent, Debug, NewS,
  +	      TimerRefs, NewTimerTypes, NewCancelTimers,
   	      Events, Event, NextState, NewData, Actions, EnterCall);
   	{Class,Reason,Stacktrace} ->
   	    terminate(
  
positive.code:     [Item].
  
  %% Cancel timer if running, otherwise no op
  cancel_timer_by_type(TimerType, TimerRefs, TimerTypes) ->
      case TimerTypes of
  	#{TimerType := TimerRef} ->
  	    cancel_timer(TimerRef),
  	    {maps:remove(TimerRef, TimerRefs),
  	     maps:remove(TimerType, TimerTypes)};
  	#{} ->
  	    {TimerRefs,TimerTypes}
      end.
  
  cancel_timer(TRef) ->
      case erlang:cancel_timer(TRef) of
  	false ->
  	    %% We have to assume that TRef is the ref of a running timer
  	    %% and if so the timer has expired
  	    %% hence we must wait for the timeout message
  	    receive
  		{timeout,TRef,_} ->
  		    ok
  	    end;
  	_TimeLeft ->
  	    ok
      end.
  
negative.code: 	  data := Data,
  	  postponed := P},
      loop_event(
        Parent, Debug, NewS, TimerRefs, TimerTypes, CancelTimers,
        Events, Event, Hibernate).
  
  
  
  