Theory Lock_Circular_Buffer
section ‹Circular-Buffer Queue-Lock›
text ‹This theory imports Annotated Commands to access the rely-guarantee
library extensions, and also imports the Abstract Queue Lock to access
the definitions of the type-synonym @{text thread_id} and the abbreviation
@{text at_head}.›
theory Lock_Circular_Buffer
imports
RG_Annotated_Commands
Lock_Abstract_Queue
begin
type_synonym index = nat
datatype flag_status = Pending | Granted
text ‹We assume a fixed number of threads, and the size of the
circular array is 1 larger the number of threads.›
consts NumThreads :: nat
abbreviation ArraySize :: "nat" where
"ArraySize ≡ NumThreads + 1"
text ‹The state of the Circular Buffer Lock consists of the following fields:
\begin{itemize}
\item @{text myindex}:
a function that maps each thread to an array-index
(where the array is modelled by @{text flag_mapping} below).
\item @{text flag_mapping}:
an array of size @{text ArraySize} that stores values of type
@{type flag_status}.
\item @{text tail}:
an index representing the tail of the queue, used when a
thread enqueues.
\item @{text aux_head}:
an auxiliary variable that stores the index used by the thread at
the head of the queue; the head of the queue spins
on the flag @{text ‹flag_mapping aux_head›}.
\item @{text aux_queue}: the auxiliary queue of threads.
\item @{text aux_mid_release}:
an auxiliary variable that signals if a thread has executed the
first instruction of \isa{release}, but not the second.
\end{itemize}›