Lably
Skip to content

Safety and liveness properties

Concepts in theoretical computer science

  • 5 min read
  • 3 chapters

Related on Lably

Through Distributed computing, Correctness (computer science) and Topology

A program is totally correct with respect to a precondition P and postcondition Q if any execution started in a state satisfying P terminates in a state satisfying Q. Total correctness is a conjunction of a safety property and a liveness property:

  • The safety property prohibits these "bad things": executions that start in a state satisfying P and terminate in a final state that does not satisfy Q. For a program C, this safety property is usually written using the Hoare triple {P}C{Q}.
  • The liveness property, the "good thing", is that execution that starts in a state satisfying P terminates.

Note that a bad thing is discrete, since it happens at a particular place during execution. A "good thing" need not be discrete, but the liveness property of termination is discrete.

Formal definitions that were ultimately proposed for safety properties and liveness properties demonstrated that this decomposition is not only intuitively appealing but is also complete: all properties of an execution are a conjunction of safety and liveness properties. Moreover, undertaking the decomposition can be helpful, because the formal definitions enable a proof that different methods must be used for verifying safety properties versus for verifying liveness properties.

Safety

A safety property proscribes discrete bad things from occurring during an execution. A safety property thus characterizes what is permitted by stating what is prohibited. The requirement that the bad thing be discrete means that a bad thing occurring during execution necessarily occurs at some identifiable point.

Examples of a discrete bad thing that could be used to define a safety property include:

  • An execution that starts in a state satisfying a given precondition terminates, but the final state does not satisfy the required postcondition;
  • An execution of two concurrent processes, where the program counters for both processes designate statements within a critical section;
  • An execution of two concurrent processes where each process is waiting for another to change state (known as deadlock).

An execution of a program can be described formally by giving the infinite sequence of program states that results as execution proceeds, where the last state for a terminating program is repeated infinitely. For a program of interest, let S denote the set of possible program states, S∗ denote the set of finite sequences of program states, and Sω denote the set of infinite sequences of program states. The relation σ≤τ holds for sequences σ and τ iff σ is a prefix of τ or σ equals τ.

A property of a program is the set of allowed executions.

The essential characteristic of a safety property SP is: If some execution σ does not satisfy SP then the defining bad thing for that safety property occurs at some point in σ. Notice that after such a bad thing, if further execution results in an execution σ′, then σ′ also does not satisfy SP, since the bad thing in σ also occurs in σ′. We take this inference about the irremediability of bad things to be the defining characteristic for SP to be a safety property. Formalizing this in predicate logic gives a formal definition for SP being a safety property.

∀σ∈Sω:σ∉SP⟹(∃β≤σ:(∀τ∈Sω:βτ∉SP))

This formal definition for safety properties implies that if an execution σ satisfies a safety property SP then every prefix of σ (with the last state repeated) also satisfies SP.

Sign in to keep reading

2 more chapters are free with a Lably account.

More in Computing and communication