Changeset e0e2f02 for doc


Ignore:
Timestamp:
May 2, 2023, 11:13:21 AM (13 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, ast-experimental, master
Children:
e9fffb1
Parents:
21d1c9c
Message:

small updates

File:
1 edited

Legend:

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

    r21d1c9c re0e2f02  
    55% ======================================================================
    66
    7 The mutual exclusion problem was introduced by Dijkstra in 1965~\cite{Dijkstra65,Dijkstra65a}.
    8 There are several concurrent processes or threads that communicate by shared variables and from time to time need exclusive access to shared resources.
     7The mutual exclusion problem was introduced by Dijkstra in 1965~\cite{Dijkstra65,Dijkstra65a}:
     8there are several concurrent processes or threads that communicate by shared variables and from time to time need exclusive access to shared resources.
    99A shared resource and code manipulating it form a pairing called a \Newterm{critical section (CS)}, which is a many-to-one relationship;
    1010\eg if multiple files are being written to by multiple threads, only the pairings of simultaneous writes to the same files are CSs.
     
    2727\section{Monitor}
    2828\CFA provides a high-level locking object, called a \Newterm{monitor}, an elegant, efficient, high-level mechanisms for mutual exclusion and synchronization for shared-memory systems.
    29 First proposed by Brinch Hansen~\cite{Hansen73} and later described and extended by C.A.R.~Hoare~\cite{Hoare74}, several concurrent programming languages provide monitors as an explicit language construct: \eg Concurrent Pascal~\cite{ConcurrentPascal}, Mesa~\cite{Mesa}, Turing~\cite{Turing:old}, Modula-3~\cite{Modula-3}, \uC~\cite{Buhr92a} and Java~\cite{Java}.
     29First proposed by Brinch Hansen~\cite{Hansen73} and later described and extended by C.A.R.~Hoare~\cite{Hoare74}.
     30Several concurrent programming languages provide monitors as an explicit language construct: \eg Concurrent Pascal~\cite{ConcurrentPascal}, Mesa~\cite{Mesa}, Turing~\cite{Turing:old}, Modula-3~\cite{Modula-3}, \uC~\cite{Buhr92a} and Java~\cite{Java}.
    3031In addition, operating-system kernels and device drivers have a monitor-like structure, although they often use lower-level primitives such as mutex locks or semaphores to manually implement a monitor.
    3132
    3233Figure~\ref{f:AtomicCounter} shows a \CFA and Java monitor implementing an atomic counter.
    3334A \Newterm{monitor} is a programming technique that implicitly binds mutual exclusion to static function scope by call and return.
    34 Lock mutual exclusion, defined by acquire/release calls, is independent of lexical context (analogous to block versus heap storage allocation).
     35In contrast, lock mutual exclusion, defined by acquire/release calls, is independent of lexical context (analogous to block versus heap storage allocation).
    3536Restricting acquire and release points in a monitor eases programming, comprehension, and maintenance, at a slight cost in flexibility and efficiency.
    3637Ultimately, a monitor is implemented using a combination of basic locks and atomic instructions.
     
    271272The @scoped_lock@ uses a deadlock avoidance algorithm where all locks after the first are acquired using @try_lock@ and if any of the lock attempts fail, all acquired locks are released.
    272273This repeats after selecting a new starting point in a cyclic manner until all locks are acquired successfully.
    273 This deadlock avoidance algorithm is shown in Listing~\ref{l:cc_deadlock_avoid}.
     274This deadlock avoidance algorithm is shown in Figure~\ref{f:cc_deadlock_avoid}.
    274275The algorithm is taken directly from the source code of the @<mutex>@ header, with some renaming and comments for clarity.
    275276
    276 \begin{cfa}[caption={\CC \lstinline{scoped_lock} deadlock avoidance algorithm},label={l:cc_deadlock_avoid}]
     277\begin{figure}
     278\begin{cfa}
    277279int first = 0;  // first lock to attempt to lock
    278280do {
     
    291293} while ( ! locks[first].owns_lock() );  $\C{// is first lock held?}$
    292294\end{cfa}
    293 
    294 While the algorithm in \ref{l:cc_deadlock_avoid} successfully avoids deadlock, there is a livelock scenario.
     295\caption{\CC \lstinline{scoped_lock} deadlock avoidance algorithm}
     296\label{f:cc_deadlock_avoid}
     297\end{figure}
     298
     299While this algorithm successfully avoids deadlock, there is a livelock scenario.
    295300Assume two threads, $A$ and $B$, create a @scoped_lock@ accessing two locks, $L1$ and $L2$.
    296301A livelock can form as follows.
     
    335340\end{cquote}
    336341Comparatively, if the @scoped_lock@ is used and the same locks are acquired elsewhere, there is no concern of the @scoped_lock@ deadlocking, due to its avoidance scheme, but it may livelock.
    337 The convenience and safety of the @mutex@ statement, \eg guaranteed lock release with exceptions, should encourage programmers to always use it for locking, mitigating any deadlock scenario.
     342The convenience and safety of the @mutex@ statement, \eg guaranteed lock release with exceptions, should encourage programmers to always use it for locking, mitigating any deadlock scenario versus combining manual locking with the mutex statement.
    338343
    339344\section{Performance}
     
    383388For example, on the AMD machine with 32 threads and 8 locks, the benchmarks would occasionally livelock indefinitely, with no threads making any progress for 3 hours before the experiment was terminated manually.
    384389It is likely that shorter bouts of livelock occurred in many of the experiments, which would explain large confidence intervals for some of the data points in the \CC data.
    385 In Figures~\ref{f:mutex_bench8_AMD} and \ref{f:mutex_bench8_Intel} the mutex statement performs better than the baseline.
    386 At 7 locks and above the mutex statement switches from a hard coded sort to insertion sort.
    387 It is likely that the improvement in throughput compared to baseline is due to the time spent in the insertion sort, which decreases contention on the locks.
     390In Figures~\ref{f:mutex_bench8_AMD} and \ref{f:mutex_bench8_Intel} there is the counter-intuitive result of the mutex statement performing better than the baseline.
     391At 7 locks and above the mutex statement switches from a hard coded sort to insertion sort, which should decrease performance.
     392It is likely the increase in throughput compared to baseline is due to the delay spent in the insertion sort, which decreases contention on the locks.
    388393
    389394\begin{figure}
Note: See TracChangeset for help on using the changeset viewer.