Changeset e0e2f02 for doc/theses/colby_parsons_MMAth/text
- Timestamp:
- May 2, 2023, 11:13:21 AM (2 years ago)
- Branches:
- ADT, ast-experimental, master
- Children:
- e9fffb1
- Parents:
- 21d1c9c
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified doc/theses/colby_parsons_MMAth/text/mutex_stmt.tex ¶
r21d1c9c re0e2f02 5 5 % ====================================================================== 6 6 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.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. 9 9 A shared resource and code manipulating it form a pairing called a \Newterm{critical section (CS)}, which is a many-to-one relationship; 10 10 \eg if multiple files are being written to by multiple threads, only the pairings of simultaneous writes to the same files are CSs. … … 27 27 \section{Monitor} 28 28 \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}. 29 First proposed by Brinch Hansen~\cite{Hansen73} and later described and extended by C.A.R.~Hoare~\cite{Hoare74}. 30 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}. 30 31 In 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. 31 32 32 33 Figure~\ref{f:AtomicCounter} shows a \CFA and Java monitor implementing an atomic counter. 33 34 A \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).35 In contrast, lock mutual exclusion, defined by acquire/release calls, is independent of lexical context (analogous to block versus heap storage allocation). 35 36 Restricting acquire and release points in a monitor eases programming, comprehension, and maintenance, at a slight cost in flexibility and efficiency. 36 37 Ultimately, a monitor is implemented using a combination of basic locks and atomic instructions. … … 271 272 The @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. 272 273 This 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}.274 This deadlock avoidance algorithm is shown in Figure~\ref{f:cc_deadlock_avoid}. 274 275 The algorithm is taken directly from the source code of the @<mutex>@ header, with some renaming and comments for clarity. 275 276 276 \begin{cfa}[caption={\CC \lstinline{scoped_lock} deadlock avoidance algorithm},label={l:cc_deadlock_avoid}] 277 \begin{figure} 278 \begin{cfa} 277 279 int first = 0; // first lock to attempt to lock 278 280 do { … … 291 293 } while ( ! locks[first].owns_lock() ); $\C{// is first lock held?}$ 292 294 \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 299 While this algorithm successfully avoids deadlock, there is a livelock scenario. 295 300 Assume two threads, $A$ and $B$, create a @scoped_lock@ accessing two locks, $L1$ and $L2$. 296 301 A livelock can form as follows. … … 335 340 \end{cquote} 336 341 Comparatively, 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 .342 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 versus combining manual locking with the mutex statement. 338 343 339 344 \section{Performance} … … 383 388 For 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. 384 389 It 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 performsbetter 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 th at the improvement in throughput compared to baseline is due to the timespent in the insertion sort, which decreases contention on the locks.390 In 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. 391 At 7 locks and above the mutex statement switches from a hard coded sort to insertion sort, which should decrease performance. 392 It 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. 388 393 389 394 \begin{figure}
Note: See TracChangeset
for help on using the changeset viewer.