- Timestamp:
- Apr 4, 2023, 9:50:07 AM (22 months ago)
- Branches:
- ADT, ast-experimental, master
- Children:
- 59c05958
- Parents:
- e8b1f23c
- Location:
- doc/theses/colby_parsons_MMAth
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/theses/colby_parsons_MMAth/style/style.tex
re8b1f23c r9363b1b 3 3 \lstset{language=CFA} % default language 4 4 5 \lstdefinestyle{defaultStyle}{ 6 escapeinside={@@}, 7 % basicstyle=\linespread{0.9}\tt\footnotesize, % reduce line spacing and use typewriter font 8 basicstyle=\linespread{0.9}\sf, % reduce line spacing and use typewriter font 9 % keywordstyle=\bfseries\color{blue}, 10 % keywordstyle=[2]\bfseries\color{Plum}, 11 % commentstyle=\sf\itshape\color{OliveGreen}, % green and italic comments 12 % identifierstyle=\color{identifierCol}, 13 % stringstyle=\sf\color{Mahogany}, % use sanserif font 14 stringstyle=\tt, % use sanserif font 15 mathescape=true, 16 % columns=fixed, 17 columns=fullflexible, 18 % aboveskip=4pt, % spacing above/below code block 19 % belowskip=3pt, 20 keepspaces=true, 21 tabsize=4, 22 % frame=lines, 23 literate=, 24 showlines=true, % show blank lines at end of code 25 showspaces=false, 26 showstringspaces=false, 27 showlines=true, % show blank lines at end of code 28 escapechar=\$, 29 xleftmargin=\parindentlnth, % indent code to paragraph indentation 30 moredelim=[is][\color{red}\bfseries]{**R**}{**R**}, % red highlighting 31 morekeywords=[2]{accept, signal, signal_block, wait, waitfor, waituntil}, 32 abovecaptionskip=5pt, 33 } 34 35 \lstdefinestyle{cfaStyle}{ 36 escapeinside={@@}, 37 basicstyle=\linespread{0.9}\sf, % reduce line spacing and use typewriter font 38 stringstyle=\tt, % use sanserif font 39 mathescape=true, 40 columns=fullflexible, 41 keepspaces=true, 42 tabsize=4, 43 literate=, 44 showlines=true, % show blank lines at end of code 45 showspaces=false, 46 showstringspaces=false, 47 showlines=true, % show blank lines at end of code 48 escapechar=\$, 49 xleftmargin=\parindentlnth, % indent code to paragraph indentation 50 moredelim=[is][\color{red}\bfseries]{**R**}{**R**}, % red highlighting 51 morekeywords=[2]{accept, signal, signal_block, wait, waitfor, waituntil}, 52 abovecaptionskip=5pt, 53 } 54 55 \lstnewenvironment{cfacode}[1][]{ 56 \lstset{ 57 language = CFA, 58 style=cfaStyle, 59 captionpos=b, 60 #1 61 } 62 }{} 63 64 \lstnewenvironment{cppcode}[1][]{ 65 \lstset{ 66 language = c++, 67 style=defaultStyle, 68 captionpos=b, 69 #1 70 } 71 }{} 72 73 \newcommand{\code}[1]{\lstinline[language=CFA,style=cfaStyle]{#1}} 5 \newcommand{\code}[1]{\lstinline[language=CFA]{#1}} 74 6 \newcommand{\uC}{$\mu$\CC} 75 7 -
doc/theses/colby_parsons_MMAth/text/CFA_concurrency.tex
re8b1f23c r9363b1b 17 17 A thread terminates by returning from the main routine where it starts. 18 18 19 \begin{cfa code}[tabsize=3,caption={\CFA user thread and processor creation},label={l:cfa_thd_init}]19 \begin{cfa}[tabsize=3,caption={\CFA user thread and processor creation},label={l:cfa_thd_init}] 20 20 21 21 thread my_thread {} // user thread type … … 33 33 } 34 34 35 \end{cfa code}35 \end{cfa} -
doc/theses/colby_parsons_MMAth/text/actors.tex
re8b1f23c r9363b1b 88 88 Similarly to create a message type a user must define a struct which \code{inline}'s the base \code{message} struct. 89 89 90 \begin{cfa code}90 \begin{cfa} 91 91 struct derived_actor { 92 92 inline actor; // Plan-9 C inheritance … … 118 118 return 0; 119 119 } 120 \end{cfa code}120 \end{cfa} 121 121 122 122 The above code is a simple actor program in \CFA. … … 125 125 Key things to highlight include the \code{receive} signature, and calls to \code{start_actor_system}, and \code{stop_actor_system}. 126 126 To define a behaviour for some derived actor and derived message type, one must declare a routine with the signature: 127 \begin{cfa code}127 \begin{cfa} 128 128 Allocation receive( derived_actor & receiver, derived_msg & msg ) 129 \end{cfa code}129 \end{cfa} 130 130 Where \code{derived_actor} and \code{derived_msg} can be any derived actor and derived message types respectively. 131 131 The return value of \code{receive} must be a value from the \code{Allocation} enum: 132 \begin{cfa code}132 \begin{cfa} 133 133 enum Allocation { Nodelete, Delete, Destroy, Finished }; 134 \end{cfa code}134 \end{cfa} 135 135 The \code{Allocation} enum is a set of actions that dictate what the executor should do with a message or actor after a given behaviour has been completed. 136 136 In the case of an actor, the \code{receive} routine returns the \code{Allocation} status to the executor which sets the status on the actor and takes the appropriate action. 137 137 For messages, they either default to \code{Nodelete}, or they can be passed an \code{Allocation} via the \code{message} constructor. 138 138 Message state can be updated via a call to: 139 \begin{cfa code}139 \begin{cfa} 140 140 void set_allocation( message & this, Allocation state ) 141 \end{cfa code}141 \end{cfa} 142 142 143 143 The following describes the use of each of the \code{Allocation} values: … … 186 186 All message sends are done using the left shift operater, \ie <<, similar to the syntax of \CC's output. 187 187 The signature of the left shift operator is: 188 \begin{cfa code}188 \begin{cfa} 189 189 Allocation ?<<?( derived_actor & receiver, derived_msg & msg ) 190 \end{cfa code}190 \end{cfa} 191 191 192 192 An astute eye will notice that this is the same signature as the \code{receive} routine which is no coincidence. … … 368 368 To first verify sequential correctness, consider the equivalent sequential swap below: 369 369 370 \begin{cfa code}370 \begin{cfa} 371 371 void swap( uint victim_idx, uint my_idx ) { 372 372 // Step 0: … … 380 380 request_queues[my_idx] = vic_queue; 381 381 } 382 \end{cfa code}382 \end{cfa} 383 383 384 384 Step 1 is missing in the sequential example since in only matter in the concurrent context presented later. … … 386 386 Temporary copies of each pointer being swapped are stored, and then the original values of each pointer are set using the copy of the other pointer. 387 387 388 \begin{cfa code}388 \begin{cfa} 389 389 // This routine is atomic 390 390 bool CAS( work_queue ** ptr, work_queue ** old, work_queue * new ) { … … 427 427 return true; 428 428 } 429 \end{cfa code}\label{c:swap}429 \end{cfa}\label{c:swap} 430 430 431 431 Now consider the concurrent implementation of the swap. -
doc/theses/colby_parsons_MMAth/text/channels.tex
re8b1f23c r9363b1b 118 118 Also note that in the Go version~\ref{l:go_chan_bar}, the size of the barrier channels has to be larger than in the \CFA version to ensure that the main thread does not block when attempting to clear the barrier. 119 119 120 \begin{cfa code}[tabsize=3,caption={\CFA channel barrier termination},label={l:cfa_chan_bar}]120 \begin{cfa}[tabsize=3,caption={\CFA channel barrier termination},label={l:cfa_chan_bar}] 121 121 struct barrier { 122 122 channel( int ) barWait; … … 171 171 return 0; 172 172 } 173 \end{cfa code}174 175 \begin{cfa code}[tabsize=3,caption={Go channel barrier termination},label={l:go_chan_bar}]173 \end{cfa} 174 175 \begin{cfa}[tabsize=3,caption={Go channel barrier termination},label={l:go_chan_bar}] 176 176 177 177 struct barrier { … … 237 237 return 0; 238 238 } 239 \end{cfa code}239 \end{cfa} 240 240 241 241 In Listing~\ref{l:cfa_resume} an example of channel closing with resumption is used. … … 244 244 If the same program was implemented in Go it would require explicit synchronization with both producers and consumers by some mechanism outside the channel to ensure that all elements were removed before task termination. 245 245 246 \begin{cfa code}[tabsize=3,caption={\CFA channel resumption usage},label={l:cfa_resume}]246 \begin{cfa}[tabsize=3,caption={\CFA channel resumption usage},label={l:cfa_resume}] 247 247 channel( int ) chan{ 128 }; 248 248 … … 280 280 return 0; 281 281 } 282 \end{cfa code}282 \end{cfa} 283 283 284 284 \section{Performance} -
doc/theses/colby_parsons_MMAth/text/mutex_stmt.tex
re8b1f23c r9363b1b 12 12 Additionally, 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}. 13 13 14 \begin{cfa code}[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}] 15 15 owner_lock lock1, lock2, lock3; 16 16 int count = 0; … … 20 20 } 21 21 mutex( lock2, lock3 ) count++; // or inline statement 22 \end{cfa code}22 \end{cfa} 23 23 24 24 \section{Other Languages} … … 32 32 An example of \CC scoped\_lock usage is shown in Listing~\ref{l:cc_scoped_lock}. 33 33 34 \begin{c ppcode}[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}] 35 35 std::mutex lock1, lock2, lock3; 36 36 { … … 38 38 // locks are released via raii at end of scope 39 39 } 40 \end{c ppcode}40 \end{cfa} 41 41 42 42 \section{\CFA implementation} … … 58 58 This use case is shown in Listing~\ref{l:sout}. 59 59 60 \begin{cfa code}[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}] 61 61 mutex( sout ) 62 62 sout | "This output is protected by mutual exclusion!"; 63 \end{cfa code}63 \end{cfa} 64 64 65 65 \section{Deadlock Avoidance} … … 70 70 The algorithm presented is taken directly from the source code of the \code{<mutex>} header, with some renaming and comments for clarity. 71 71 72 \begin{c ppcode}[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}] 73 73 int first = 0; // first lock to attempt to lock 74 74 do { … … 86 86 // if first lock is still held then all have been acquired 87 87 } while (!locks[first].owns_lock()); // is first lock held? 88 \end{c ppcode}88 \end{cfa} 89 89 90 90 The 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.