﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc	field_blocks	field_dependson	field_seealso
558	More flexible locking scheme for fibril timers	Jiri Svoboda	Jiri Svoboda	"Once #556 is addressed, we get a timer that provides reasonable mutual-exclusion guarantees, but slightly inflexible with respect to locking.

As an example, imagine we implement a state machine that reacts to events and timeouts. It has a state A. Upon reception of event E the machine transitions to state B. If the event B does not come for a specified amount of time, the state machine transitions to state C.

We implement the state machine using state variable S, state lock SL and a timeout timer T.

Event E received:
  * lock SL
  * if S == A then clear T; S := B
  * unlock SL

Timeout T expires:
  * lock SL
  * S := C
  * unlock SL

Obviously S must be accessed with SL held. Now the T.lock is held when T handler is invoked. That means lock order T.lock -> SL. However we must clear T while holding SL. That means lock order SL -> T.lock and we get a deadlock.

In other words it is not possible to hold a lock L while setting or clearing the timer if L is taken inside the timer handler.

With the current fibril timer interface, there seems to be no way of breaking this deadlock and keeping the correctness/mutual exclusion of state transitions.

"	enhancement	closed	major	0.6.0	helenos/lib/c	mainline	fixed					#556, #557
