Ignore:
Timestamp:
Apr 4, 2023, 10:12:57 PM (15 months ago)
Author:
Mike Brooks <mlbrooks@…>
Branches:
ADT, ast-experimental, master
Children:
9bb8ee42
Parents:
ff71057 (diff), bb7422a (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/theses/colby_parsons_MMAth/text/mutex_stmt.tex

    rff71057 re02e13f  
    1212Additionally, it provides the safety guarantee of deadlock-freedom, both by acquiring the locks in a deadlock-free manner, and by ensuring that the locks release on error, or normal program execution via \gls{raii}.
    1313
    14 \begin{cfacode}[tabsize=3,caption={\CFA mutex statement usage},label={l:cfa_mutex_ex}]
     14\begin{cfa}[tabsize=3,caption={\CFA mutex statement usage},label={l:cfa_mutex_ex}]
    1515owner_lock lock1, lock2, lock3;
    1616int count = 0;
     
    2020}
    2121mutex( lock2, lock3 ) count++; // or inline statement
    22 \end{cfacode}
     22\end{cfa}
    2323
    2424\section{Other Languages}
     
    3232An example of \CC scoped\_lock usage is shown in Listing~\ref{l:cc_scoped_lock}.
    3333
    34 \begin{cppcode}[tabsize=3,caption={\CC scoped\_lock usage},label={l:cc_scoped_lock}]
     34\begin{cfa}[tabsize=3,caption={\CC scoped\_lock usage},label={l:cc_scoped_lock}]
    3535std::mutex lock1, lock2, lock3;
    3636{
     
    3838    // locks are released via raii at end of scope
    3939}
    40 \end{cppcode}
     40\end{cfa}
    4141
    4242\section{\CFA implementation}
     
    5858This use case is shown in Listing~\ref{l:sout}.
    5959
    60 \begin{cfacode}[tabsize=3,caption={\CFA sout with mutex statement},label={l:sout}]
     60\begin{cfa}[tabsize=3,caption={\CFA sout with mutex statement},label={l:sout}]
    6161mutex( sout )
    6262    sout | "This output is protected by mutual exclusion!";
    63 \end{cfacode}
     63\end{cfa}
    6464
    6565\section{Deadlock Avoidance}
     
    7070The algorithm presented is taken directly from the source code of the \code{<mutex>} header, with some renaming and comments for clarity.
    7171
    72 \begin{cppcode}[caption={\CC scoped\_lock deadlock avoidance algorithm},label={l:cc_deadlock_avoid}]
     72\begin{cfa}[caption={\CC scoped\_lock deadlock avoidance algorithm},label={l:cc_deadlock_avoid}]
    7373int first = 0;  // first lock to attempt to lock
    7474do {
     
    8686// if first lock is still held then all have been acquired
    8787} while (!locks[first].owns_lock());  // is first lock held?
    88 \end{cppcode}
     88\end{cfa}
    8989
    9090The algorithm in \ref{l:cc_deadlock_avoid} successfully avoids deadlock, however there is a potential livelock scenario.
Note: See TracChangeset for help on using the changeset viewer.