Ignore:
Timestamp:
Apr 4, 2023, 9:50:07 AM (14 months ago)
Author:
caparsons <caparson@…>
Branches:
ADT, ast-experimental, master
Children:
59c05958
Parents:
e8b1f23c
Message:

removed code style and refactored to use cfa code style

Location:
doc/theses/colby_parsons_MMAth
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • doc/theses/colby_parsons_MMAth/style/style.tex

    re8b1f23c r9363b1b  
    33\lstset{language=CFA}                                   % default language
    44
    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}}
    746\newcommand{\uC}{$\mu$\CC}
    757
  • doc/theses/colby_parsons_MMAth/text/CFA_concurrency.tex

    re8b1f23c r9363b1b  
    1717A thread terminates by returning from the main routine where it starts.
    1818
    19 \begin{cfacode}[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}]
    2020
    2121thread my_thread {}     // user thread type
     
    3333}
    3434
    35 \end{cfacode}
     35\end{cfa}
  • doc/theses/colby_parsons_MMAth/text/actors.tex

    re8b1f23c r9363b1b  
    8888Similarly to create a message type a user must define a struct which \code{inline}'s the base \code{message} struct.
    8989
    90 \begin{cfacode}
     90\begin{cfa}
    9191struct derived_actor {
    9292    inline actor;       // Plan-9 C inheritance
     
    118118    return 0;
    119119}
    120 \end{cfacode}
     120\end{cfa}
    121121
    122122The above code is a simple actor program in \CFA.
     
    125125Key things to highlight include the \code{receive} signature, and calls to \code{start_actor_system}, and \code{stop_actor_system}.
    126126To define a behaviour for some derived actor and derived message type, one must declare a routine with the signature:
    127 \begin{cfacode}
     127\begin{cfa}
    128128Allocation receive( derived_actor & receiver, derived_msg & msg )
    129 \end{cfacode}
     129\end{cfa}
    130130Where \code{derived_actor} and \code{derived_msg} can be any derived actor and derived message types respectively.
    131131The return value of \code{receive} must be a value from the \code{Allocation} enum:
    132 \begin{cfacode}
     132\begin{cfa}
    133133enum Allocation { Nodelete, Delete, Destroy, Finished };
    134 \end{cfacode}
     134\end{cfa}
    135135The \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.
    136136In 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.
    137137For messages, they either default to \code{Nodelete}, or they can be passed an \code{Allocation} via the \code{message} constructor.
    138138Message state can be updated via a call to:
    139 \begin{cfacode}
     139\begin{cfa}
    140140void set_allocation( message & this, Allocation state )
    141 \end{cfacode}
     141\end{cfa}
    142142
    143143The following describes the use of each of the \code{Allocation} values:
     
    186186All message sends are done using the left shift operater, \ie <<, similar to the syntax of \CC's output.
    187187The signature of the left shift operator is:
    188 \begin{cfacode}
     188\begin{cfa}
    189189Allocation ?<<?( derived_actor & receiver, derived_msg & msg )
    190 \end{cfacode}
     190\end{cfa}
    191191
    192192An astute eye will notice that this is the same signature as the \code{receive} routine which is no coincidence.
     
    368368To first verify sequential correctness, consider the equivalent sequential swap below:
    369369
    370 \begin{cfacode}
     370\begin{cfa}
    371371void swap( uint victim_idx, uint my_idx  ) {
    372372    // Step 0:
     
    380380    request_queues[my_idx] = vic_queue;
    381381}
    382 \end{cfacode}
     382\end{cfa}
    383383
    384384Step 1 is missing in the sequential example since in only matter in the concurrent context presented later.
     
    386386Temporary 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.
    387387
    388 \begin{cfacode}
     388\begin{cfa}
    389389// This routine is atomic
    390390bool CAS( work_queue ** ptr, work_queue ** old, work_queue * new ) {
     
    427427    return true;
    428428}
    429 \end{cfacode}\label{c:swap}
     429\end{cfa}\label{c:swap}
    430430
    431431Now consider the concurrent implementation of the swap.
  • doc/theses/colby_parsons_MMAth/text/channels.tex

    re8b1f23c r9363b1b  
    118118Also 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.
    119119
    120 \begin{cfacode}[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}]
    121121struct barrier {
    122122    channel( int ) barWait;
     
    171171    return 0;
    172172}
    173 \end{cfacode}
    174 
    175 \begin{cfacode}[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}]
    176176
    177177struct barrier {
     
    237237    return 0;
    238238}
    239 \end{cfacode}
     239\end{cfa}
    240240
    241241In Listing~\ref{l:cfa_resume} an example of channel closing with resumption is used.
     
    244244If 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.
    245245
    246 \begin{cfacode}[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}]
    247247channel( int ) chan{ 128 };
    248248
     
    280280    return 0;
    281281}
    282 \end{cfacode}
     282\end{cfa}
    283283
    284284\section{Performance}
  • doc/theses/colby_parsons_MMAth/text/mutex_stmt.tex

    re8b1f23c r9363b1b  
    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.