Index: doc/bibliography/pl.bib
===================================================================
--- doc/bibliography/pl.bib	(revision 6f774be1d5e97d459b38dc756b61b836cddc73f0)
+++ doc/bibliography/pl.bib	(revision 8421d3fad6379460563c3a8922889a72c4d868fe)
@@ -1209,5 +1209,5 @@
     year	= 2018,
     pages	= {2111-2146},
-    note	= {\href{http://dx.doi.org/10.1002/spe.2624}{http://\-dx.doi.org/\-10.1002/\-spe.2624}},
+    optnote	= {\href{http://dx.doi.org/10.1002/spe.2624}{http://\-dx.doi.org/\-10.1002/\-spe.2624}},
 }
 
@@ -1870,5 +1870,5 @@
     month	= sep,
     year	= 2020,
-    note	= {\href{https://plg.uwaterloo.ca/~usystem/pub/uSystem/uC++.pdf}{https://\-plg.uwaterloo.ca/\-$\sim$usystem/\-pub/\-uSystem/uC++.pdf}},
+    note	= {\url{https://plg.uwaterloo.ca/~usystem/pub/uSystem/uC++.pdf}},
 }
 
@@ -2004,5 +2004,5 @@
     number	= 5,
     pages	= {1005-1042},
-    note	= {\href{https://onlinelibrary.wiley.com/doi/10.1002/spe.2925}{https://\-onlinelibrary.wiley.com/\-doi/\-10.1002/\-spe.2925}},
+    optnote	= {\href{https://onlinelibrary.wiley.com/doi/10.1002/spe.2925}{https://\-onlinelibrary.wiley.com/\-doi/\-10.1002/\-spe.2925}},
 }
 
@@ -4223,4 +4223,5 @@
     title	= {Implementing Lock-Free Queues},
     booktitle	= {Seventh International Conference on Parallel and Distributed Computing Systems},
+    organization= {International Society for Computers and Their Applications},
     address	= {Las Vegas, Nevada, U.S.A.},
     year	= {1994},
@@ -5086,5 +5087,5 @@
 }
 
-@manual{MMTk,
+@misc{MMTk,
     keywords	= {Java memory management},
     contributer	= {pabuhr@plg},
@@ -5093,6 +5094,5 @@
     month	= sep,
     year	= 2006,
-    note	= {\href{http://cs.anu.edu.au/~Robin.Garner/mmtk-guide.pdf}
-    		  {http://cs.anu.edu.au/\-$\sim$Robin.Garner/\-mmtk-guide.pdf}},
+    howpublished= {\url{http://cs.anu.edu.au/~Robin.Garner/mmtk-guide.pdf}},
 }
 
@@ -7402,4 +7402,12 @@
 }
 
+@misc{rpmalloc,
+    author	= {Mattias Jansson},
+    title	= {rpmalloc version 1.4.1},
+    month	= apr,
+    year	= 2022,
+    howpublished= {\href{https://github.com/mjansson/rpmalloc}{https://\-github.com/\-mjansson/\-rpmalloc}},
+}
+
 @manual{Rust,
     keywords	= {Rust programming language},
@@ -7456,5 +7464,5 @@
     booktitle	= {PLDI '04: Proceedings of the ACM SIGPLAN 2004 Conference on Programming Language Design and Implementation},
     location	= {Washington DC, USA},
-    publisher	= {ACM},
+    organization= {ACM},
     address	= {New York, NY, USA},
     volume	= 39,
Index: doc/theses/colby_parsons_MMAth/Makefile
===================================================================
--- doc/theses/colby_parsons_MMAth/Makefile	(revision 6f774be1d5e97d459b38dc756b61b836cddc73f0)
+++ doc/theses/colby_parsons_MMAth/Makefile	(revision 8421d3fad6379460563c3a8922889a72c4d868fe)
@@ -98,5 +98,5 @@
 
 ${BASE}.dvi : Makefile ${GRAPHS} ${PROGRAMS} ${PICTURES} ${FIGURES} ${SOURCES} ${DATA} \
-		style/style.tex ${Macros}/common.tex ${Macros}/indexstyle local.bib ../../bibliography/pl.bib | ${Build}
+		glossary.tex style/style.tex ${Macros}/common.tex ${Macros}/indexstyle local.bib ../../bibliography/pl.bib | ${Build}
 	# Must have *.aux file containing citations for bibtex
 	if [ ! -r ${basename $@}.aux ] ; then ${LaTeX} ${basename $@}.tex ; fi
Index: doc/theses/colby_parsons_MMAth/glossary.tex
===================================================================
--- doc/theses/colby_parsons_MMAth/glossary.tex	(revision 6f774be1d5e97d459b38dc756b61b836cddc73f0)
+++ doc/theses/colby_parsons_MMAth/glossary.tex	(revision 8421d3fad6379460563c3a8922889a72c4d868fe)
@@ -32,8 +32,8 @@
 % Examples from template above
 
-\newabbreviation{raii}{RAII}{Resource Acquisition Is Initialization}
-\newabbreviation{rtti}{RTTI}{Run-Time Type Information}
-\newabbreviation{fcfs}{FCFS}{First Come First Served}
-\newabbreviation{toctou}{TOCTOU}{time-of-check to time-of-use}
+\newabbreviation{raii}{RAII}{\Newterm{resource acquisition is initialization}}
+\newabbreviation{rtti}{RTTI}{\Newterm{run-time type information}}
+\newabbreviation{fcfs}{FCFS}{\Newterm{first-come first-served}}
+\newabbreviation{toctou}{TOCTOU}{\Newterm{time-of-check to time-of-use}}
 
 \newglossaryentry{actor}
Index: doc/theses/colby_parsons_MMAth/style/style.tex
===================================================================
--- doc/theses/colby_parsons_MMAth/style/style.tex	(revision 6f774be1d5e97d459b38dc756b61b836cddc73f0)
+++ doc/theses/colby_parsons_MMAth/style/style.tex	(revision 8421d3fad6379460563c3a8922889a72c4d868fe)
@@ -15,4 +15,9 @@
 \newsavebox{\myboxB}
 
+\lstnewenvironment{Golang}[1][]
+{\lstset{language=Go,literate={<-}{\makebox[2ex][c]{\textless\raisebox{0.4ex}{\rule{0.8ex}{0.075ex}}}}2,
+	moredelim=**[is][\protect\color{red}]{@}{@}}\lstset{#1}}
+{}
+
 \lstnewenvironment{java}[1][]
 {\lstset{language=java,moredelim=**[is][\protect\color{red}]{@}{@}}\lstset{#1}}
Index: doc/theses/colby_parsons_MMAth/text/channels.tex
===================================================================
--- doc/theses/colby_parsons_MMAth/text/channels.tex	(revision 6f774be1d5e97d459b38dc756b61b836cddc73f0)
+++ doc/theses/colby_parsons_MMAth/text/channels.tex	(revision 8421d3fad6379460563c3a8922889a72c4d868fe)
@@ -17,5 +17,5 @@
 Additionally all channel operations in CSP are synchronous (no buffering).
 Advanced channels as a programming language feature has been popularized in recent years by the language Go~\cite{Go}, which encourages the use of channels as its fundamental concurrent feature.
-It was the popularity of Go channels that lead to their implemention in \CFA.
+It was the popularity of Go channels that lead to their implementation in \CFA.
 Neither Go nor \CFA channels have the restrictions of the early channel-based concurrent systems.
 
@@ -61,21 +61,26 @@
 \section{Channel Implementation}
 Currently, only the Go programming language provides user-level threading where the primary communication mechanism is channels.
-Experiments were conducted that varied the producer-consumer problem algorithm and lock type used inside the channel.
+Experiments were conducted that varied the producer-consumer algorithm and lock type used inside the channel.
 With the exception of non-\gls{fcfs} or non-FIFO algorithms, no algorithm or lock usage in the channel implementation was found to be consistently more performant that Go's choice of algorithm and lock implementation.
 Performance of channels can be improved by sharding the underlying buffer \cite{Dice11}. 
-In doing so the FIFO property is lost, which is undesireable for user-facing channels.
+However, the FIFO property is lost, which is undesirable for user-facing channels.
 Therefore, the low-level channel implementation in \CFA is largely copied from the Go implementation, but adapted to the \CFA type and runtime systems.
 As such the research contributions added by \CFA's channel implementation lie in the realm of safety and productivity features.
 
-The Go channel implementation utilitizes cooperation between threads to achieve good performance~\cite{go:chan}.
-The cooperation between threads only occurs when producers or consumers need to block due to the buffer being full or empty.
-In these cases the blocking thread stores their relevant data in a shared location and the signalling thread will complete their operation before waking them.
-This helps improve performance in a few ways.
-First, each thread interacting with the channel with only acquire and release the internal channel lock exactly once.
-This decreases contention on the internal lock, as only entering threads will compete for the lock since signalled threads never reacquire the lock.
-The other advantage of the cooperation approach is that it eliminates the potential bottleneck of waiting for signalled threads.
-The property of acquiring/releasing the lock only once can be achieved without cooperation by \Newterm{baton passing} the lock.
-Baton passing is when one thread acquires a lock but does not release it, and instead signals a thread inside the critical section conceptually "passing" the mutual exclusion to the signalled thread.
-While baton passing is useful in some algorithms, it results in worse performance than the cooperation approach in channel implementations since all entering threads then need to wait for the blocked thread to reach the front of the ready queue and run before other operations on the channel can proceed.
+The Go channel implementation utilizes cooperation among threads to achieve good performance~\cite{go:chan}.
+This cooperation only occurs when producers or consumers need to block due to the buffer being full or empty.
+In these cases, a blocking thread stores their relevant data in a shared location and the signalling thread completes the blocking thread's operation before waking them;
+\ie the blocking thread has no work to perform after it unblocks because the signalling threads has done this work.
+This approach is similar to wait morphing for locks~\cite[p.~82]{Butenhof97} and improves performance in a few ways.
+First, each thread interacting with the channel only acquires and releases the internal channel lock once.
+As a result, contention on the internal lock is decreased, as only entering threads compete for the lock as unblocking threads do not reacquire the lock.
+The other advantage of Go's wait-morphing approach is that it eliminates the bottleneck of waiting for signalled threads to run.
+Note, the property of acquiring/releasing the lock only once can also be achieved with a different form of cooperation, called \Newterm{baton passing}.
+Baton passing occurs when one thread acquires a lock but does not release it, and instead signals a thread inside the critical section, conceptually ``passing'' the mutual exclusion from the signalling thread to the signalled thread.
+The baton-passing approach has threads cooperate to pass mutual exclusion without additional lock acquires or releases;
+the wait-morphing approach has threads cooperate by completing the signalled thread's operation, thus removing a signalled thread's need for mutual exclusion after unblocking.
+While baton passing is useful in some algorithms, it results in worse channel performance than the Go approach.
+In the baton-passing approach, all threads need to wait for the signalled thread to reach the front of the ready queue, context switch, and run before other operations on the channel can proceed, since the signalled thread holds mutual exclusion;
+in the wait-morphing approach, since the operation is completed before the signal, other threads can continue to operate on the channel without waiting for the signalled thread to run.
 
 In this work, all channel sizes \see{Sections~\ref{s:ChannelSize}} are implemented with bounded buffers.
@@ -100,34 +105,33 @@
 \subsection{Toggle-able Statistics}
 As discussed, a channel is a concurrent layer over a bounded buffer.
-To achieve efficient buffering users should aim for as few blocking operations on a channel as possible.
-Often to achieve this users may change the buffer size, shard a channel into multiple channels, or tweak the number of producer and consumer threads.
-Fo users to be able to make informed decisions when tuning channel usage, toggle-able channel statistics are provided.
-The statistics are toggled at compile time via the @CHAN_STATS@ macro to ensure that they are entirely elided when not used.
-When statistics are turned on, four counters are maintained per channel, two for producers and two for consumers.
+To achieve efficient buffering, users should aim for as few blocking operations on a channel as possible.
+Mechanisms to reduce blocking are: change the buffer size, shard a channel into multiple channels, or tweak the number of producer and consumer threads.
+For users to be able to make informed decisions when tuning channel usage, toggle-able channel statistics are provided.
+The statistics are toggled on during the \CFA build by defining the @CHAN_STATS@ macro, which guarantees zero cost when not using this feature.
+When statistics are turned on, four counters are maintained per channel, two for inserting (producers) and two for removing (consumers).
 The two counters per type of operation track the number of blocking operations and total operations.
-In the channel destructor the counters are printed out aggregated and also per type of operation.
-An example use case of the counters follows.
-A user is buffering information between producer and consumer threads and wants to analyze channel performance.
-Via the statistics they see that producers block for a large percentage of their operations while consumers do not block often.
-They then can use this information to adjust their number of producers/consumers or channel size to achieve a larger percentage of non-blocking producer operations, thus increasing their channel throughput.
+In the channel destructor, the counters are printed out aggregated and also per type of operation.
+An example use case is noting that producer inserts are blocking often while consumer removes do not block often.
+This information can be used to increase the number of consumers to decrease the blocking producer operations, thus increasing the channel throughput.
+Whereas, increasing the channel size in this scenario is unlikely to produce a benefit because the consumers can never keep up with the producers.
 
 \subsection{Deadlock Detection}
-The deadlock detection in the \CFA channels is fairly basic.
-It only detects the case where threads are blocked on the channel during deallocation.
-This case is guaranteed to deadlock since the list holding the blocked thread is internal to the channel and will be deallocated.
-If a user maintained a separate reference to a thread and unparked it outside the channel they could avoid the deadlock, but would run into other runtime errors since the thread would access channel data after waking that is now deallocated.
-More robust deadlock detection surrounding channel usage would have to be implemented separate from the channel implementation since it would require knowledge about the threading system and other channel/thread state.
+The deadlock detection in the \CFA channels is fairly basic but detects a very common channel mistake during termination.
+That is, it detects the case where threads are blocked on the channel during channel deallocation.
+This case is guaranteed to deadlock since there are no producer threads to supply values needed by the waiting consumer threads.
+Only if a user maintained a separate reference to the consumer threads and manually unblocks them outside the channel could the deadlock be avoid.
+However, without special consumer semantics, this unblocking would generate other runtime errors where the consumer attempts to access non-existing channel data or even a deallocated channel.
+More robust deadlock detection needs to be implemented separate from channels since it requires knowledge about the threading system and other channel/thread state.
 
 \subsection{Program Shutdown}
 Terminating concurrent programs is often one of the most difficult parts of writing concurrent code, particularly if graceful termination is needed.
-The difficulty of graceful termination often arises from the usage of synchronization primitives that need to be handled carefully during shutdown.
+The difficulty for graceful termination often arises from the usage of synchronization primitives that need to be handled carefully during shutdown.
 It is easy to deadlock during termination if threads are left behind on synchronization primitives.
 Additionally, most synchronization primitives are prone to \gls{toctou} issues where there is race between one thread checking the state of a concurrent object and another thread changing the state.
 \gls{toctou} issues with synchronization primitives often involve a race between one thread checking the primitive for blocked threads and another thread blocking on it.
 Channels are a particularly hard synchronization primitive to terminate since both sending and receiving to/from a channel can block.
-Thus, improperly handled \gls{toctou} issues with channels often result in deadlocks as threads trying to perform the termination may end up unexpectedly blocking in their attempt to help other threads exit the system.
-
-\paragraph{Go channels} provide a set of tools to help with concurrent shutdown~\cite{go:chan}.
-Channels in Go have a @close@ operation and a \Go{select} statement that both can be used to help threads terminate.
+Thus, improperly handled \gls{toctou} issues with channels often result in deadlocks as threads performing the termination may end up unexpectedly blocking in their attempt to help other threads exit the system.
+
+\paragraph{Go channels} provide a set of tools to help with concurrent shutdown~\cite{go:chan} using a @close@ operation in conjunction with the \Go{select} statement.
 The \Go{select} statement is discussed in \ref{s:waituntil}, where \CFA's @waituntil@ statement is compared with the Go \Go{select} statement.
 
@@ -143,10 +147,10 @@
 Note, panics in Go can be caught, but it is not the idiomatic way to write Go programs.
 
-While Go's channel closing semantics are powerful enough to perform any concurrent termination needed by a program, their lack of ease of use leaves much to be desired.
+While Go's channel-closing semantics are powerful enough to perform any concurrent termination needed by a program, their lack of ease of use leaves much to be desired.
 Since both closing and sending panic once a channel is closed, a user often has to synchronize the senders (producers) before the channel can be closed to avoid panics.
 However, in doing so it renders the @close@ operation nearly useless, as the only utilities it provides are the ability to ensure receivers no longer block on the channel and receive zero-valued elements.
 This functionality is only useful if the zero-typed element is recognized as a sentinel value, but if another sentinel value is necessary, then @close@ only provides the non-blocking feature.
 To avoid \gls{toctou} issues during shutdown, a busy wait with a \Go{select} statement is often used to add or remove elements from a channel.
-Due to Go's asymmetric approach to channel shutdown, separate synchronization between producers and consumers of a channel has to occur during shutdown.
+Hence, due to Go's asymmetric approach to channel shutdown, separate synchronization between producers and consumers of a channel has to occur during shutdown.
 
 \paragraph{\CFA channels} have access to an extensive exception handling mechanism~\cite{Beach21}.
@@ -161,46 +165,25 @@
 When a channel in \CFA is closed, all subsequent calls to the channel raise a resumption exception at the caller.
 If the resumption is handled, the caller attempts to complete the channel operation.
-However, if channel operation would block, a termination exception is thrown.
+However, if the channel operation would block, a termination exception is thrown.
 If the resumption is not handled, the exception is rethrown as a termination.
 These termination exceptions allow for non-local transfer that is used to great effect to eagerly and gracefully shut down a thread.
 When a channel is closed, if there are any blocked producers or consumers inside the channel, they are woken up and also have a resumption thrown at them.
-The resumption exception, @channel_closed@, has a couple fields to aid in handling the exception.
-The exception contains a pointer to the channel it was thrown from, and a pointer to an element.
-In exceptions thrown from remove the element pointer will be null.
-In the case of insert the element pointer points to the element that the thread attempted to insert.
+The resumption exception, @channel_closed@, has internal fields to aid in handling the exception.
+The exception contains a pointer to the channel it is thrown from and a pointer to a buffer element.
+For exceptions thrown from @remove@, the buffer element pointer is null.
+For exceptions thrown from @insert@, the element pointer points to the buffer element that the thread attempted to insert.
 This element pointer allows the handler to know which operation failed and also allows the element to not be lost on a failed insert since it can be moved elsewhere in the handler.
-Furthermore, due to \CFA's powerful exception system, this data can be used to choose handlers based which channel and operation failed.
-Exception handlers in \CFA have an optional predicate after the exception type which can be used to optionally trigger or skip handlers based on the content of an exception.
-It is worth mentioning that the approach of exceptions for termination may incur a larger performance cost during termination that the approach used in Go.
-This should not be an issue, since termination is rarely an fast-path of an application and ensuring that termination can be implemented correctly with ease is the aim of the exception approach.
+Furthermore, due to \CFA's powerful exception system, this data can be used to choose handlers based on which channel and operation failed.
+For example, exception handlers in \CFA have an optional predicate which can be used to trigger or skip handlers based on the content of the matching exception.
+It is worth mentioning that using exceptions for termination may incur a larger performance cost than the Go approach.
+However, this should not be an issue, since termination is rarely on the fast-path of an application.
+In contrast, ensuring termination can be easily implemented correctly is the aim of the exception approach.
 
 \section{\CFA / Go channel Examples}
-To highlight the differences between \CFA's and Go's close semantics, three examples will be presented.
+To highlight the differences between \CFA's and Go's close semantics, three examples are presented.
 The first example is a simple shutdown case, where there are producer threads and consumer threads operating on a channel for a fixed duration.
-Once the duration ends, producers and consumers terminate without worrying about any leftover values in the channel.
-The second example extends the first example by requiring the channel to be empty upon shutdown.
+Once the duration ends, producers and consumers terminate immediately leaving unprocessed elements in the channel.
+The second example extends the first by requiring the channel to be empty after shutdown.
 Both the first and second example are shown in Figure~\ref{f:ChannelTermination}.
-
-
-First the Go solutions to these examples shown in Figure~\ref{l:go_chan_term} are discussed.
-Since some of the elements being passed through the channel are zero-valued, closing the channel in Go does not aid in communicating shutdown.
-Instead, a different mechanism to communicate with the consumers and producers needs to be used.
-This use of an additional flag or communication method is common in Go channel shutdown code, since to avoid panics on a channel, the shutdown of a channel often has to be communicated with threads before it occurs.
-In this example, a flag is used to communicate with producers and another flag is used for consumers.
-Producers and consumers need separate avenues of communication both so that producers terminate before the channel is closed to avoid panicking, and to avoid the case where all the consumers terminate first, which can result in a deadlock for producers if the channel is full.
-The producer flag is set first, then after producers terminate the consumer flag is set and the channel is closed.
-In the second example where all values need to be consumed, the main thread iterates over the closed channel to process any remaining values.
-
-
-In the \CFA solutions in Figure~\ref{l:cfa_chan_term}, shutdown is communicated directly to both producers and consumers via the @close@ call.
-In the first example where all values do not need to be consumed, both producers and consumers do not handle the resumption and finish once they receive the termination exception.
-The second \CFA example where all values must be consumed highlights how resumption is used with channel shutdown.
-The @Producer@ thread-main knows to stop producing when the @insert@ call on a closed channel raises exception @channel_closed@.
-The @Consumer@ thread-main knows to stop consuming after all elements of a closed channel are removed and the call to @remove@ would block.
-Hence, the consumer knows the moment the channel closes because a resumption exception is raised, caught, and ignored, and then control returns to @remove@ to return another item from the buffer.
-Only when the buffer is drained and the call to @remove@ would block, a termination exception is raised to stop consuming.
-The \CFA semantics allow users to communicate channel shutdown directly through the channel, without having to share extra state between threads.
-Additionally, when the channel needs to be drained, \CFA provides users with easy options for processing the leftover channel values in the main thread or in the consumer threads.
-If one wishes to consume the leftover values in the consumer threads in Go, extra synchronization between the main thread and the consumer threads is needed.
 
 \begin{figure}
@@ -208,111 +191,129 @@
 
 \begin{lrbox}{\myboxA}
+\begin{Golang}[aboveskip=0pt,belowskip=0pt]
+var channel chan int = make( chan int, 128 )
+var prodJoin chan int = make( chan int, 4 )
+var consJoin chan int = make( chan int, 4 )
+var cons_done, prod_done bool = false, false;
+func producer() {
+	for {
+		if prod_done { break }
+		channel <- 5
+	}
+	prodJoin <- 0 // synch with main thd
+}
+
+func consumer() {
+	for {
+		if cons_done { break }
+		<- channel
+	}
+	consJoin <- 0 // synch with main thd
+}
+
+
+func main() {
+	for j := 0; j < 4; j++ { go consumer() }
+	for j := 0; j < 4; j++ { go producer() }
+	time.Sleep( time.Second * 10 )
+	prod_done = true
+	for j := 0; j < 4 ; j++ { <- prodJoin }
+	cons_done = true
+	close(channel) // ensure no cons deadlock
+	@for elem := range channel {@
+		// process leftover values
+	@}@
+	for j := 0; j < 4; j++ { <- consJoin }
+}
+\end{Golang}
+\end{lrbox}
+
+\begin{lrbox}{\myboxB}
 \begin{cfa}[aboveskip=0pt,belowskip=0pt]
-channel( size_t ) Channel{ ChannelSize };
-
+channel( size_t ) chan{ 128 };
 thread Consumer {};
+thread Producer {};
+
+void main( Producer & this ) {
+	try {
+		for ()
+			insert( chan, 5 );
+	} catch( channel_closed * ) {
+		// unhandled resume or full
+	}
+}
 void main( Consumer & this ) {
-    try {
-        for ( ;; )
-            remove( Channel );
-    @} catchResume( channel_closed * ) { @
-    // handled resume => consume from chan
-    } catch( channel_closed * ) {
-        // empty or unhandled resume
-    } 
-}
-
-thread Producer {};
-void main( Producer & this ) {
-    size_t count = 0;
-    try {
-        for ( ;; )
-            insert( Channel, count++ );
-    } catch ( channel_closed * ) {
-        // unhandled resume or full
-    } 
-}
-
-int main( int argc, char * argv[] ) {
-    Consumer c[Consumers];
-    Producer p[Producers];
-    sleep(Duration`s);
-    close( Channel );
-    return 0;
-}
+	try {
+		for () { int i = remove( chan ); }
+	@} catchResume( channel_closed * ) {@
+		// handled resume => consume from chan
+	} catch( channel_closed * ) {
+		// empty or unhandled resume
+	}
+}
+int main() {
+	Consumer c[4];
+	Producer p[4];
+	sleep( 10`s );
+	close( chan );
+}
+
+
+
+
+
+
+
 \end{cfa}
 \end{lrbox}
 
-\begin{lrbox}{\myboxB}
-\begin{cfa}[aboveskip=0pt,belowskip=0pt]
-var cons_done, prod_done bool = false, false;
-var prodJoin chan int = make(chan int, Producers)
-var consJoin chan int = make(chan int, Consumers)
-
-func consumer( channel chan uint64 ) {
-    for {
-        if cons_done { break }
-        <-channel
-    }
-    consJoin <- 0 // synch with main thd
-}
-
-func producer( channel chan uint64 ) {
-    var count uint64 = 0
-    for {
-        if prod_done { break }
-        channel <- count++
-    }
-    prodJoin <- 0 // synch with main thd
-}
-
-func main() {
-    channel = make(chan uint64, ChannelSize)
-    for j := 0; j < Consumers; j++ {
-        go consumer( channel )
-    }
-    for j := 0; j < Producers; j++ {
-        go producer( channel )
-    }
-    time.Sleep(time.Second * Duration)
-    prod_done = true
-    for j := 0; j < Producers ; j++ {
-        <-prodJoin // wait for prods
-    }
-    cons_done = true
-    close(channel) // ensure no cons deadlock
-    @for elem := range channel { @
-        // process leftover values
-    @}@
-    for j := 0; j < Consumers; j++{
-        <-consJoin // wait for cons
-    }
-}
-\end{cfa}
-\end{lrbox}
-
-\subfloat[\CFA style]{\label{l:cfa_chan_term}\usebox\myboxA}
+\subfloat[Go style]{\label{l:go_chan_term}\usebox\myboxA}
 \hspace*{3pt}
 \vrule
 \hspace*{3pt}
-\subfloat[Go style]{\label{l:go_chan_term}\usebox\myboxB}
+\subfloat[\CFA style]{\label{l:cfa_chan_term}\usebox\myboxB}
 \caption{Channel Termination Examples 1 and 2. Code specific to example 2 is highlighted.}
 \label{f:ChannelTermination}
 \end{figure}
 
-The final shutdown example uses channels to implement a barrier.
-It is shown in Figure~\ref{f:ChannelBarrierTermination}.
-The problem of implementing a barrier is chosen since threads are both producers and consumers on the barrier-internal channels, which removes the ability to easily synchronize producers before consumers during shutdown.
-As such, while the shutdown details will be discussed with this problem in mind, they are also applicable to other problems taht have individual threads both producing and consuming from channels.
-Both of these examples are implemented using \CFA syntax so that they can be easily compared.
-Figure~\ref{l:cfa_chan_bar} uses \CFA-style channel close semantics and Figure~\ref{l:go_chan_bar} uses Go-style close semantics.
-In this example it is infeasible to use the Go @close@ call since all threads are both potentially producers and consumers, causing panics on close to be unavoidable without complex synchronization.
-As such in Figure~\ref{l:go_chan_bar} to implement a flush routine for the buffer, a sentinel value of @-1@ has to be used to indicate to threads that they need to leave the barrier.
-This sentinel value has to be checked at two points.
+Figure~\ref{l:go_chan_term} shows the Go solution.
+Since some of the elements being passed through the channel are zero-valued, closing the channel in Go does not aid in communicating shutdown.
+Instead, a different mechanism to communicate with the consumers and producers needs to be used.
+Flag variables are common in Go-channel shutdown-code to avoid panics on a channel, meaning the channel shutdown has to be communicated with threads before it occurs.
+Hence, the two flags @cons_done@ and @prod_done@ are used to communicate with the producers and consumers, respectively.
+Furthermore, producers and consumers need separate shutdown channels so producers terminate before the channel is closed to avoid panicking, and to avoid the case where all the consumers terminate first, which can result in a deadlock for producers if the channel is full.
+The producer flag is set first;
+then after all producers terminate, the consumer flag is set and the channel is closed leaving elements in the buffer.
+To purge the buffer, a loop is added (red) that iterates over the closed channel to process any remaining values.
+
+Figure~\ref{l:cfa_chan_term} shows the \CFA solution.
+Here, shutdown is communicated directly to both producers and consumers via the @close@ call.
+A @Producer@ thread knows to stop producing when the @insert@ call on a closed channel raises exception @channel_closed@.
+If a @Consumer@ thread ignores the first resumption exception from the @close@, the exception is reraised as a termination exception and elements are left in the buffer.
+If a @Consumer@ thread handles the resumptions exceptions (red), control returns to complete the remove.
+A @Consumer@ thread knows to stop consuming after all elements of a closed channel are removed and the consumer would block, which causes a termination raise of @channel_closed@.
+The \CFA semantics allow users to communicate channel shutdown directly through the channel, without having to share extra state between threads.
+Additionally, when the channel needs to be drained, \CFA provides users with easy options for processing the leftover channel values in the main thread or in the consumer threads.
+
+Figure~\ref{f:ChannelBarrierTermination} shows a final shutdown example using channels to implement a barrier.
+A Go and \CFA style solution are presented but both are implemented using \CFA syntax so they can be easily compared.
+Implementing a barrier is interesting because threads are both producers and consumers on the barrier-internal channels, @entryWait@ and @barWait@.
+The outline for the barrier implementation starts by initially filling the @entryWait@ channel with $N$ tickets in the barrier constructor, allowing $N$ arriving threads to remove these values and enter the barrier.
+After @entryWait@ is empty, arriving threads block when removing.
+However, the arriving threads that entered the barrier cannot leave the barrier until $N$ threads have arrived.
+Hence, the entering threads block on the empty @barWait@ channel until the $N$th arriving thread inserts $N-1$ elements into @barWait@ to unblock the $N-1$ threads calling @remove@.
+The race between these arriving threads blocking on @barWait@ and the $N$th thread inserting values into @barWait@ does not affect correctness;
+\ie an arriving thread may or may not block on channel @barWait@ to get its value.
+Finally, the last thread to remove from @barWait@ with ticket $N-2$, refills channel @entryWait@ with $N$ values to start the next group into the barrier.
+
+Now, the two channels makes termination synchronization between producers and consumers difficult.
+Interestingly, the shutdown details for this problem are also applicable to other problems with threads producing and consuming from the same channel.
+The Go-style solution cannot use the Go @close@ call since all threads are both potentially producers and consumers, causing panics on close to be unavoidable without complex synchronization.
+As such in Figure \ref{l:go_chan_bar}, a flush routine is needed to insert a sentinel value, @-1@, to inform threads waiting in the buffer they need to leave the barrier.
+This sentinel value has to be checked at two points along the fast-path and sentinel values daisy-chained into the buffers.
 Furthermore, an additional flag @done@ is needed to communicate to threads once they have left the barrier that they are done.
-
-In the \CFA version~\ref{l:cfa_chan_bar}, the barrier shutdown results in an exception being thrown at threads operating on it, which informs the threads that they must terminate.
+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.
+For The \CFA solution~\ref{l:cfa_chan_bar}, the barrier shutdown results in an exception being thrown at threads operating on it, to inform waiting threads they must leave the barrier.
 This avoids the need to use a separate communication method other than the barrier, and avoids extra conditional checks on the fast path of the barrier implementation.
-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.
 
 \begin{figure}
@@ -320,4 +321,53 @@
 
 \begin{lrbox}{\myboxA}
+\begin{cfa}[aboveskip=0pt,belowskip=0pt]
+struct barrier {
+	channel( int ) barWait, entryWait;
+	int size;
+};
+void ?{}( barrier & this, int size ) with(this) {
+	barWait{size + 1};   entryWait{size + 1};
+	this.size = size;
+	for ( i; size )
+		insert( entryWait, i );
+}
+void wait( barrier & this ) with(this) {
+	int ticket = remove( entryWait );
+	@if ( ticket == -1 ) { insert( entryWait, -1 ); return; }@
+	if ( ticket == size - 1 ) {
+		for ( i; size - 1 )
+			insert( barWait, i );
+		return;
+	}
+	ticket = remove( barWait );
+	@if ( ticket == -1 ) { insert( barWait, -1 ); return; }@
+	if ( size == 1 || ticket == size - 2 ) { // last ?
+		for ( i; size )
+			insert( entryWait, i );
+	}
+}
+void flush(barrier & this) with(this) {
+	@insert( entryWait, -1 );   insert( barWait, -1 );@
+}
+enum { Threads = 4 };
+barrier b{Threads};
+@bool done = false;@
+thread Thread {};
+void main( Thread & this ) {
+	for () {
+	  @if ( done ) break;@
+		wait( b );
+	}
+}
+int main() {
+	Thread t[Threads];
+	sleep(10`s);
+	done = true;
+	flush( b );
+} // wait for threads to terminate
+\end{cfa}
+\end{lrbox}
+
+\begin{lrbox}{\myboxB}
 \begin{cfa}[aboveskip=0pt,belowskip=0pt]
 struct barrier {
@@ -368,58 +418,9 @@
 \end{lrbox}
 
-\begin{lrbox}{\myboxB}
-\begin{cfa}[aboveskip=0pt,belowskip=0pt]
-struct barrier {
-	channel( int ) barWait, entryWait;
-	int size;
-};
-void ?{}( barrier & this, int size ) with(this) {
-	barWait{size + 1};   entryWait{size + 1};
-	this.size = size;
-	for ( i; size )
-		insert( entryWait, i );
-}
-void wait( barrier & this ) with(this) {
-	int ticket = remove( entryWait );
-	@if ( ticket == -1 ) { insert( entryWait, -1 ); return; }@
-	if ( ticket == size - 1 ) {
-		for ( i; size - 1 )
-			insert( barWait, i );
-		return;
-	}
-	ticket = remove( barWait );
-	@if ( ticket == -1 ) { insert( barWait, -1 ); return; }@
-	if ( size == 1 || ticket == size - 2 ) { // last ?
-		for ( i; size )
-			insert( entryWait, i );
-	}
-}
-void flush(barrier & this) with(this) {
-	@insert( entryWait, -1 );   insert( barWait, -1 );@
-}
-enum { Threads = 4 };
-barrier b{Threads};
-@bool done = false;@
-thread Thread {};
-void main( Thread & this ) {
-	for () {
-	  @if ( done ) break;@
-		wait( b );
-	}
-}
-int main() {
-	Thread t[Threads];
-	sleep(10`s);
-	done = true;
-	flush( b );
-} // wait for threads to terminate
-\end{cfa}
-\end{lrbox}
-
-\subfloat[\CFA style]{\label{l:cfa_chan_bar}\usebox\myboxA}
+\subfloat[Go style]{\label{l:go_chan_bar}\usebox\myboxA}
 \hspace*{3pt}
 \vrule
 \hspace*{3pt}
-\subfloat[Go style]{\label{l:go_chan_bar}\usebox\myboxB}
+\subfloat[\CFA style]{\label{l:cfa_chan_bar}\usebox\myboxB}
 \caption{Channel Barrier Termination}
 \label{f:ChannelBarrierTermination}
Index: doc/theses/colby_parsons_MMAth/thesis.tex
===================================================================
--- doc/theses/colby_parsons_MMAth/thesis.tex	(revision 6f774be1d5e97d459b38dc756b61b836cddc73f0)
+++ doc/theses/colby_parsons_MMAth/thesis.tex	(revision 8421d3fad6379460563c3a8922889a72c4d868fe)
@@ -111,7 +111,8 @@
     colorlinks=true,        % false: boxed links; true: colored links
     linkcolor=blue,         % color of internal links
-    citecolor=blue,        % color of links to bibliography
+    citecolor=blue,         % color of links to bibliography
     filecolor=magenta,      % color of file links
-    urlcolor=cyan           % color of external links
+    urlcolor=cyan,          % color of external links
+    breaklinks=true
 }
 \ifthenelse{\boolean{PrintVersion}}{   % for improved print quality, change some hyperref options
@@ -126,4 +127,5 @@
 % \usepackage[acronym]{glossaries}
 \usepackage[automake,toc,abbreviations]{glossaries-extra} % Exception to the rule of hyperref being the last add-on package
+\renewcommand*{\glstextformat}[1]{\textcolor{black}{#1}}
 % If glossaries-extra is not in your LaTeX distribution, get it from CTAN (http://ctan.org/pkg/glossaries-extra), 
 % although it's supposed to be in both the TeX Live and MikTeX distributions. There are also documentation and 
Index: driver/cfa.cc
===================================================================
--- driver/cfa.cc	(revision 6f774be1d5e97d459b38dc756b61b836cddc73f0)
+++ driver/cfa.cc	(revision 8421d3fad6379460563c3a8922889a72c4d868fe)
@@ -10,6 +10,6 @@
 // Created On       : Tue Aug 20 13:44:49 2002
 // Last Modified By : Peter A. Buhr
-// Last Modified On : Tue May 23 16:22:47 2023
-// Update Count     : 477
+// Last Modified On : Tue May 30 10:47:52 2023
+// Update Count     : 478
 //
 
@@ -329,4 +329,7 @@
 	#endif // __x86_64__
 
+	// ARM -mno-outline-atomics => use LL/SC instead of calls to atomic routines: __aarch64_swp_acq_rel, __aarch64_cas8_acq_rel
+	// ARM -march=armv8.2-a+lse => generate Arm LSE extension instructions SWAP and CAS
+	// https://community.arm.com/developer/tools-software/tools/b/tools-software-ides-blog/posts/making-the-most-of-the-arm-architecture-in-gcc-10
 	#ifdef __ARM_ARCH
 	args[nargs++] = "-mno-outline-atomics";				// use ARM LL/SC instructions for atomics
Index: tests/concurrency/lockfree_stack.cfa
===================================================================
--- tests/concurrency/lockfree_stack.cfa	(revision 6f774be1d5e97d459b38dc756b61b836cddc73f0)
+++ tests/concurrency/lockfree_stack.cfa	(revision 8421d3fad6379460563c3a8922889a72c4d868fe)
@@ -10,6 +10,6 @@
 // Created On       : Thu May 25 15:36:50 2023
 // Last Modified By : Peter A. Buhr
-// Last Modified On : Fri May 26 08:08:47 2023
-// Update Count     : 4
+// Last Modified On : Tue May 30 19:02:32 2023
+// Update Count     : 18
 // 
 
@@ -20,5 +20,5 @@
 struct Node;											// forward declaration
 union Link {
-	struct {											// 64-bit x 2
+	struct {											// 32/64-bit x 2
 		Node * volatile top;							// pointer to stack top
 		uintptr_t count;								// count each push
@@ -57,20 +57,27 @@
 Stack stack;											// global stack
 
+enum { Times =
+	#if defined( __ARM_ARCH )							// ARM CASV is very slow
+	10_000
+	#else
+	1_000_000
+	#endif // __arm_64__
+};
+
 thread Worker {};
 void main( Worker & w ) {
-	for ( i; 100000 ) {
-		Node & n = *pop( stack );
+	for ( i; Times ) {
+		Node & n = *pop( stack );						// pop any node
 		assert( &n != NULL );
-		n.next.top = 0p;								// shrub fields
+		n.next.top = 0p;								// scrub fields
 		n.next.count = 0;
 		//yield( rand() % 3 );
-		push( stack, n );
+		push( stack, n );								// push it back
 	}
 }
 
-
 int main() {
-	enum { N = 10 };
-	processor p[N - 1];									// kernel threads
+	enum { N = 8 };										// kernel threads
+	processor p[N - 1];									// add kernel threads
 
 	for ( i; N ) {										// push N values on stack
