Locking: Small Example

The lower left pane contains the original program, and the lower right pane contains the program with qualifier annotations.

In this example, the functions spin_lock and spin_unlock, which contain magic assembly code (omitted), are called to acquire and release a lock, respectively. The main function first acquires and then releases rtc_lock.

In the lower right pane we've added qualifiers $locked and $unlocked indicating that spin_lock and spin_unlock require their arguments be in the correct state. We've also added change_type statements to capture the effect of the assembly code. The expression change_type(x, type) is treated exactly like an assignment to x, except rather than giving an expression for the right-hand side you only need to supply the type of the right-hand side. We also declare that in the initial environment, rtc_lock is $unlocked.