Changeset e02e13f for doc/theses/colby_parsons_MMAth/text/actors.tex
- Timestamp:
- Apr 4, 2023, 10:12:57 PM (18 months ago)
- 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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/theses/colby_parsons_MMAth/text/actors.tex
rff71057 re02e13f 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.
Note: See TracChangeset
for help on using the changeset viewer.