Index: doc/papers/concurrency/Paper.tex
===================================================================
--- doc/papers/concurrency/Paper.tex	(revision 95487027f53dabc24b643cfc26071635ae66fab5)
+++ doc/papers/concurrency/Paper.tex	(revision 08b5a7e1a102828f77a6d1ca83545b58e44614d2)
@@ -56,10 +56,6 @@
 \newcommand{\Textbf}[2][red]{{\color{#1}{\textbf{#2}}}}
 \newcommand{\Emph}[2][red]{{\color{#1}\textbf{\emph{#2}}}}
-\newcommand{\R}[1]{\Textbf{#1}}
-\newcommand{\B}[1]{{\Textbf[blue]{#1}}}
-\newcommand{\G}[1]{{\Textbf[OliveGreen]{#1}}}
 \newcommand{\uC}{$\mu$\CC}
-\newcommand{\cit}{\textsuperscript{[Citation Needed]}\xspace}
-\newcommand{\TODO}{{\Textbf{TODO}}}
+\newcommand{\TODO}[1]{{\Textbf{#1}}}
 
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -258,5 +254,5 @@
 \section{Introduction}
 
-This paper provides a minimal concurrency \newterm{Abstract Program Interface} (API) that is simple, efficient and can be used to build other concurrency features.
+This paper provides a minimal concurrency \newterm{Application Program Interface} (API) that is simple, efficient and can be used to build other concurrency features.
 While the simplest concurrency system is a thread and a lock, this low-level approach is hard to master.
 An easier approach for programmers is to support higher-level constructs as the basis of concurrency.
@@ -587,5 +583,5 @@
 As such, library support for threading is far from widespread.
 At the time of writing the paper, neither \protect\lstinline|gcc| nor \protect\lstinline|clang| support ``threads.h'' in their standard libraries.}.
-On modern architectures, a lack of threading is unacceptable~\cite{Sutter05, Sutter05b}, and therefore existing and new programming languages must have tools for writing efficient concurrent programs to take advantage of parallelism.
+In modern programming languages, a lack of threading is unacceptable~\cite{Sutter05, Sutter05b}, and therefore existing and new programming languages must have tools for writing efficient concurrent programs to take advantage of parallelism.
 As an extension of C, \CFA needs to express these concepts in a way that is as natural as possible to programmers familiar with imperative languages.
 Furthermore, because C is a system-level language, programmers expect to choose precisely which features they need and which cost they are willing to pay.
@@ -625,5 +621,5 @@
 \newbox\myboxA
 \begin{lrbox}{\myboxA}
-\begin{lstlisting}[aboveskip=0pt,belowskip=0pt]
+\begin{cfa}[aboveskip=0pt,belowskip=0pt]
 `int f1, f2, state = 1;`   // single global variables
 int fib() {
@@ -642,10 +638,10 @@
 	}
 }
-\end{lstlisting}
+\end{cfa}
 \end{lrbox}
 
 \newbox\myboxB
 \begin{lrbox}{\myboxB}
-\begin{lstlisting}[aboveskip=0pt,belowskip=0pt]
+\begin{cfa}[aboveskip=0pt,belowskip=0pt]
 #define FIB_INIT `{ 0, 1 }`
 typedef struct { int f2, f1; } Fib;
@@ -664,5 +660,5 @@
 	}
 }
-\end{lstlisting}
+\end{cfa}
 \end{lrbox}
 
@@ -677,5 +673,5 @@
 \newbox\myboxA
 \begin{lrbox}{\myboxA}
-\begin{lstlisting}[aboveskip=0pt,belowskip=0pt]
+\begin{cfa}[aboveskip=0pt,belowskip=0pt]
 `coroutine` Fib { int fn; };
 void main( Fib & fib ) with( fib ) {
@@ -697,9 +693,9 @@
 	}
 }
-\end{lstlisting}
+\end{cfa}
 \end{lrbox}
 \newbox\myboxB
 \begin{lrbox}{\myboxB}
-\begin{lstlisting}[aboveskip=0pt,belowskip=0pt]
+\begin{cfa}[aboveskip=0pt,belowskip=0pt]
 `coroutine` Fib { int ret; };
 void main( Fib & f ) with( fib ) {
@@ -721,5 +717,5 @@
 
 
-\end{lstlisting}
+\end{cfa}
 \end{lrbox}
 \subfloat[3 States, internal variables]{\label{f:Coroutine3States}\usebox\myboxA}
@@ -769,5 +765,5 @@
 \newbox\myboxA
 \begin{lrbox}{\myboxA}
-\begin{lstlisting}[aboveskip=0pt,belowskip=0pt]
+\begin{cfa}[aboveskip=0pt,belowskip=0pt]
 `coroutine` Format {
 	char ch;   // used for communication
@@ -801,10 +797,10 @@
 	}
 }
-\end{lstlisting}
+\end{cfa}
 \end{lrbox}
 
 \newbox\myboxB
 \begin{lrbox}{\myboxB}
-\begin{lstlisting}[aboveskip=0pt,belowskip=0pt]
+\begin{cfa}[aboveskip=0pt,belowskip=0pt]
 struct Format {
 	char ch;
@@ -838,5 +834,5 @@
 	format( &fmt );
 }
-\end{lstlisting}
+\end{cfa}
 \end{lrbox}
 \subfloat[\CFA Coroutine]{\label{f:CFAFmt}\usebox\myboxA}
@@ -1044,5 +1040,7 @@
 };
 \end{cfa}
-& {\Large $\Rightarrow$} &
+&
+{\Large $\Rightarrow$}
+&
 \begin{tabular}{@{}ccc@{}}
 \begin{cfa}
@@ -1445,9 +1443,9 @@
 \label{s:InternalScheduling}
 
-While monitor mutual-exclusion provides safe access to shared data, the monitor data may indicate that a thread accessing it cannot proceed, \eg a bounded buffer, Figure~\ref{f:BoundedBuffer}, may be full/empty so produce/consumer threads must block.
+While monitor mutual-exclusion provides safe access to shared data, the monitor data may indicate that a thread accessing it cannot proceed, \eg a bounded buffer, Figure~\ref{f:GenericBoundedBuffer}, may be full/empty so produce/consumer threads must block.
 Leaving the monitor and trying again (busy waiting) is impractical for high-level programming.
 Monitors eliminate busy waiting by providing internal synchronization to schedule threads needing access to the shared data, where the synchronization is blocking (threads are parked) versus spinning.
 The synchronization is generally achieved with internal~\cite{Hoare74} or external~\cite[\S~2.9.2]{uC++} scheduling, where \newterm{scheduling} is defined as indicating which thread acquires the critical section next.
-\newterm{Internal scheduling} is characterized by each thread entering the monitor and making an individual decision about proceeding or blocking, while \newterm{external scheduling} is characterized by an entering thread making a decision about proceeding for itself and behalf of other threads attempting entry.
+\newterm{Internal scheduling} is characterized by each thread entering the monitor and making an individual decision about proceeding or blocking, while \newterm{external scheduling} is characterized by an entering thread making a decision about proceeding for itself and on behalf of other threads attempting entry.
 
 Figure~\ref{f:BBInt} shows a \CFA bounded-buffer with internal scheduling, where producers/consumers enter the monitor, see the buffer is full/empty, and block on an appropriate condition lock, @full@/@empty@.
@@ -1458,13 +1456,14 @@
 \begin{enumerate}
 \item
-The signalling thread leaves immediately, and the signalled thread continues.
+The signalling thread returns immediately, and the signalled thread continues.
 \item
-The signalling thread continues and the signalled thread is marked for urgent unblocking at subsequent scheduling points (exit/wait).
+The signalling thread continues and the signalled thread is marked for urgent unblocking at the next scheduling point (exit/wait).
 \item
-The signalling thread blocks but is marked for urgrent unblocking and the signalled thread continues.
+The signalling thread blocks but is marked for urgrent unblocking at the next scheduling point and the signalled thread continues.
 \end{enumerate}
 The first approach is too restrictive, as it precludes solving a reasonable class of problems (\eg dating service).
 \CFA supports the next two semantics as both are useful.
 Finally, while it is common to store a @condition@ as a field of the monitor, in \CFA, a @condition@ variable can be created/stored independently.
+Furthermore, a condition variable is tied to a \emph{group} of monitors on first use (called \newterm{branding}), which means that using internal scheduling with distinct sets of monitors requires one condition variable per set of monitors.
 
 \begin{figure}
@@ -1472,5 +1471,5 @@
 \newbox\myboxA
 \begin{lrbox}{\myboxA}
-\begin{lstlisting}[aboveskip=0pt,belowskip=0pt]
+\begin{cfa}[aboveskip=0pt,belowskip=0pt]
 forall( otype T ) { // distribute forall
 	monitor Buffer {
@@ -1496,10 +1495,10 @@
 	}
 }
-\end{lstlisting}
+\end{cfa}
 \end{lrbox}
 
 \newbox\myboxB
 \begin{lrbox}{\myboxB}
-\begin{lstlisting}[aboveskip=0pt,belowskip=0pt]
+\begin{cfa}[aboveskip=0pt,belowskip=0pt]
 forall( otype T ) { // distribute forall
 	monitor Buffer {
@@ -1525,5 +1524,5 @@
 	}
 }
-\end{lstlisting}
+\end{cfa}
 \end{lrbox}
 
@@ -1532,5 +1531,5 @@
 \subfloat[External Scheduling]{\label{f:BBExt}\usebox\myboxB}
 \caption{Generic Bounded-Buffer}
-\label{f:BoundedBuffer}
+\label{f:GenericBoundedBuffer}
 \end{figure}
 
@@ -1538,246 +1537,119 @@
 External scheduling is controlled by the @waitfor@ statement, which atomically blocks the calling thread, releases the monitor lock, and restricts the routine calls that can next acquire mutual exclusion.
 If the buffer is full, only calls to @remove@ can acquire the buffer, and if the buffer is empty, only calls to @insert@ can acquire the buffer.
-Threads making calls to routines that are currently excluded wait outside (externally) of the monitor on a calling queue.
-
-An important aspect of monitor implementation is barging, \ie can calling threads barge ahead of signalled threads?
+Threads making calls to routines that are currently excluded block outside (externally) of the monitor on a calling queue, versus blocking on condition queues inside the monitor.
+
+Both internal and external scheduling extend to multiple monitors in a natural way.
+\begin{cfa}
+monitor M { `condition e`; ... };
+void foo( M & mutex m1, M & mutex m2 ) {
+	... wait( `e` ); ...					$\C{// wait( e, m1, m2 )}$
+	... wait( `e, m1` ); ...
+	... wait( `e, m2` ); ...
+}
+
+void rtn$\(_1\)$( M & mutex m1, M & mutex m2 );
+void rtn$\(_2\)$( M & mutex m1 );
+void bar( M & mutex m1, M & mutex m2 ) {
+	... waitfor( `rtn` ); ...				$\C{// waitfor( rtn\(_1\), m1, m2 )}$
+	... waitfor( `rtn, m1` ); ...			$\C{// waitfor( rtn\(_2\), m1 )}$
+}
+\end{cfa}
+For @wait( e )@, the default semantics is to atomically block the signaller and release all acquired mutex types in the parameter list, \ie @wait( e, m1, m2 )@.
+To override the implicit multi-monitor wait, specific mutex parameter(s) can be specified, \eg @wait( e, m1 )@.
+Wait statically verifies the released monitors are the acquired mutex-parameters so unconditional release is safe.
+Similarly, for @waitfor( rtn, ... )@, the default semantics is to atomically block the acceptor and release all acquired mutex types in the parameter list, \ie @waitfor( rtn, m1, m2 )@.
+To override the implicit multi-monitor wait, specific mutex parameter(s) can be specified, \eg @waitfor( rtn, m1 )@.
+Waitfor statically verifies the released monitors are the same as the acquired mutex-parameters of the given routine or routine pointer.
+To statically verify the released monitors match with the accepted routine's mutex parameters, the routine (pointer) prototype must be accessible.
+
+Given the ability to release a subset of acquired monitors can result in a \newterm{nested monitor}~\cite{Lister77} deadlock.
+\begin{cfa}
+void foo( M & mutex m1, M & mutex m2 ) {
+	... wait( `e, m1` ); ...				$\C{// release m1, keeping m2 acquired )}$
+void baz( M & mutex m1, M & mutex m2 ) {	$\C{// must acquire m1 and m2 )}$
+	... signal( `e` ); ...
+\end{cfa}
+The @wait@ only releases @m1@ so the signalling thread cannot acquire both @m1@ and @m2@ to  enter @baz@ to get to the @signal@.
+While deadlock issues can occur with multiple/nesting acquisition, this issue results from the fact that locks, and by extension monitors, are not perfectly composable.
+
+Finally, an important aspect of monitor implementation is barging, \ie can calling threads barge ahead of signalled threads?
 If barging is allowed, synchronization between a singller and signallee is difficult, often requiring multiple unblock/block cycles (looping around a wait rechecking if a condition is met).
-\CFA scheduling does \emph{not} have barging, which simplifies synchronization among threads in the monitor.
+\begin{quote}
+However, we decree that a signal operation be followed immediately by resumption of a waiting program, without possibility of an intervening procedure call from yet a third program.
+It is only in this way that a waiting program has an absolute guarantee that it can acquire the resource just released by the signalling program without any danger that a third program will interpose a monitor entry and seize the resource instead.~\cite[p.~550]{Hoare74}
+\end{quote}
+\CFA scheduling \emph{precludes} barging, which simplifies synchronization among threads in the monitor and increases correctness.
+For example, there are no loops in either bounded buffer solution in Figure~\ref{f:GenericBoundedBuffer}.
 Supporting barging prevention as well as extending internal scheduling to multiple monitors is the main source of complexity in the design and implementation of \CFA concurrency.
 
-Indeed, like the bulk acquire semantics, internal scheduling extends to multiple monitors in a way that is natural to the user but requires additional complexity on the implementation side.
-
-First, here is a simple example of internal scheduling:
-
-\begin{cfa}
-monitor A {
-	condition e;
-}
-
-void foo(A& mutex a1, A& mutex a2) {
+
+\subsection{Barging Prevention}
+
+Figure~\ref{f:BargingPrevention} shows \CFA code where bulk acquire adds complexity to the internal-signalling semantics.
+The complexity begins at the end of the inner @mutex@ statement, where the semantics of internal scheduling need to be extended for multiple monitors.
+The problem is that bulk acquire is used in the inner @mutex@ statement where one of the monitors is already acquired.
+When the signalling thread reaches the end of the inner @mutex@ statement, it should transfer ownership of @m1@ and @m2@ to the waiting thread to prevent barging into the outer @mutex@ statement by another thread.
+However, both the signalling and signalled threads still need monitor @m1@.
+
+\begin{figure}
+\newbox\myboxA
+\begin{lrbox}{\myboxA}
+\begin{cfa}[aboveskip=0pt,belowskip=0pt]
+monitor M m1, m2;
+condition c;
+mutex( m1 ) {
 	...
-	// Wait for cooperation from bar()
-	wait(a1.e);
+	mutex( m1, m2 ) {
+		... `wait( c )`; // block and release m1, m2
+		// m1, m2 acquired
+	} // $\LstCommentStyle{\color{red}release m2}$
+	// m1 acquired
+} // release m1
+\end{cfa}
+\end{lrbox}
+
+\newbox\myboxB
+\begin{lrbox}{\myboxB}
+\begin{cfa}[aboveskip=0pt,belowskip=0pt]
+
+
+mutex( m1 ) {
 	...
-}
-
-void bar(A& mutex a1, A& mutex a2) {
-	// Provide cooperation for foo()
-	...
-	// Unblock foo
-	signal(a1.e);
-}
-\end{cfa}
-
-% ======================================================================
-% ======================================================================
-\subsection{Internal Scheduling - Multi-Monitor}
-% ======================================================================
-% ======================================================================
-It is easy to understand the problem of multi-monitor scheduling using a series of pseudo-code examples.
-Note that for simplicity in the following snippets of pseudo-code, waiting and signalling is done using an implicit condition variable, like Java built-in monitors.
-Indeed, @wait@ statements always use the implicit condition variable as parameters and explicitly name the monitors (A and B) associated with the condition.
-Note that in \CFA, condition variables are tied to a \emph{group} of monitors on first use (called branding), which means that using internal scheduling with distinct sets of monitors requires one condition variable per set of monitors.
-The example below shows the simple case of having two threads (one for each column) and a single monitor A.
-
-\begin{multicols}{2}
-thread 1
-\begin{cfa}
-acquire A
-	wait A
-release A
-\end{cfa}
-
-\columnbreak
-
-thread 2
-\begin{cfa}
-acquire A
-	signal A
-release A
-\end{cfa}
-\end{multicols}
-One thread acquires before waiting (atomically blocking and releasing A) and the other acquires before signalling.
-It is important to note here that both @wait@ and @signal@ must be called with the proper monitor(s) already acquired.
-This semantic is a logical requirement for barging prevention.
-
-A direct extension of the previous example is a bulk acquire version:
-\begin{multicols}{2}
-\begin{cfa}
-acquire A & B
-	wait A & B
-release A & B
-\end{cfa}
-\columnbreak
-\begin{cfa}
-acquire A & B
-	signal A & B
-release A & B
-\end{cfa}
-\end{multicols}
-\noindent This version uses bulk acquire (denoted using the {\sf\&} symbol), but the presence of multiple monitors does not add a particularly new meaning.
-Synchronization happens between the two threads in exactly the same way and order.
-The only difference is that mutual exclusion covers a group of monitors.
-On the implementation side, handling multiple monitors does add a degree of complexity as the next few examples demonstrate.
-
-While deadlock issues can occur when nesting monitors, these issues are only a symptom of the fact that locks, and by extension monitors, are not perfectly composable.
-For monitors, a well-known deadlock problem is the Nested Monitor Problem~\cite{Lister77}, which occurs when a @wait@ is made by a thread that holds more than one monitor.
-For example, the following cfa-code runs into the nested-monitor problem:
-\begin{multicols}{2}
-\begin{cfa}
-acquire A
-	acquire B
-		wait B
-	release B
-release A
-\end{cfa}
-
-\columnbreak
-
-\begin{cfa}
-acquire A
-	acquire B
-		signal B
-	release B
-release A
-\end{cfa}
-\end{multicols}
-\noindent The @wait@ only releases monitor @B@ so the signalling thread cannot acquire monitor @A@ to get to the @signal@.
-Attempting release of all acquired monitors at the @wait@ introduces a different set of problems, such as releasing monitor @C@, which has nothing to do with the @signal@.
-
-However, for monitors as for locks, it is possible to write a program using nesting without encountering any problems if nesting is done correctly.
-For example, the next cfa-code snippet acquires monitors {\sf A} then {\sf B} before waiting, while only acquiring {\sf B} when signalling, effectively avoiding the Nested Monitor Problem~\cite{Lister77}.
-
-\begin{multicols}{2}
-\begin{cfa}
-acquire A
-	acquire B
-		wait B
-	release B
-release A
-\end{cfa}
-
-\columnbreak
-
-\begin{cfa}
-
-acquire B
-	signal B
-release B
-
-\end{cfa}
-\end{multicols}
-
-\noindent However, this simple refactoring may not be possible, forcing more complex restructuring.
-
-% ======================================================================
-% ======================================================================
-\subsection{Internal Scheduling - In Depth}
-% ======================================================================
-% ======================================================================
-
-A larger example is presented to show complex issues for bulk acquire and its implementation options are analyzed.
-Figure~\ref{f:int-bulk-cfa} shows an example where bulk acquire adds a significant layer of complexity to the internal signalling semantics, and listing \ref{f:int-bulk-cfa} shows the corresponding \CFA code to implement the cfa-code in listing \ref{f:int-bulk-cfa}.
-For the purpose of translating the given cfa-code into \CFA-code, any method of introducing a monitor is acceptable, \eg @mutex@ parameters, global variables, pointer parameters, or using locals with the @mutex@ statement.
-
-\begin{figure}
-\begin{multicols}{2}
-Waiting thread
-\begin{cfa}[numbers=left]
-acquire A
-	// Code Section 1
-	acquire A & B
-		// Code Section 2
-		wait A & B
-		// Code Section 3
-	release A & B
-	// Code Section 4
-release A
-\end{cfa}
-\columnbreak
-Signalling thread
-\begin{cfa}[numbers=left, firstnumber=10,escapechar=|]
-acquire A
-	// Code Section 5
-	acquire A & B
-		// Code Section 6
-		|\label{line:signal1}|signal A & B
-		// Code Section 7
-	|\label{line:releaseFirst}|release A & B
-	// Code Section 8
-|\label{line:lastRelease}|release A
-\end{cfa}
-\end{multicols}
-\begin{cfa}[caption={Internal scheduling with bulk acquire},label={f:int-bulk-cfa}]
-\end{cfa}
-\begin{center}
-\begin{cfa}[xleftmargin=.4\textwidth]
-monitor A a;
-monitor B b;
-condition c;
-\end{cfa}
-\end{center}
-\begin{multicols}{2}
-Waiting thread
-\begin{cfa}
-mutex(a) {
-	// Code Section 1
-	mutex(a, b) {
-		// Code Section 2
-		wait(c);
-		// Code Section 3
-	}
-	// Code Section 4
-}
-\end{cfa}
-\columnbreak
-Signalling thread
-\begin{cfa}
-mutex(a) {
-	// Code Section 5
-	mutex(a, b) {
-		// Code Section 6
-		signal(c);
-		// Code Section 7
-	}
-	// Code Section 8
-}
-\end{cfa}
-\end{multicols}
-\begin{cfa}[caption={Equivalent \CFA code for listing \ref{f:int-bulk-cfa}},label={f:int-bulk-cfa}]
-\end{cfa}
-\begin{multicols}{2}
-Waiter
-\begin{cfa}[numbers=left]
-acquire A
-	acquire A & B
-		wait A & B
-	release A & B
-release A
-\end{cfa}
-
-\columnbreak
-
-Signaller
-\begin{cfa}[numbers=left, firstnumber=6,escapechar=|]
-acquire A
-	acquire A & B
-		signal A & B
-	release A & B
-	|\label{line:secret}|// Secretly keep B here
-release A
-// Wakeup waiter and transfer A & B
-\end{cfa}
-\end{multicols}
-\begin{cfa}[caption={Figure~\ref{f:int-bulk-cfa}, with delayed signalling comments},label={f:int-secret}]
-\end{cfa}
+	mutex( m1, m2 ) {
+		... `signal( c )`; ...
+		// m1, m2 acquired
+	} // $\LstCommentStyle{\color{red}release m2}$
+	// m1 acquired
+} // release m1
+\end{cfa}
+\end{lrbox}
+
+\newbox\myboxC
+\begin{lrbox}{\myboxC}
+\begin{cfa}[aboveskip=0pt,belowskip=0pt]
+
+
+mutex( m1 ) {
+	... `wait( c )`; ...
+	// m1 acquired
+} // $\LstCommentStyle{\color{red}release m1}$
+
+
+
+
+\end{cfa}
+\end{lrbox}
+
+\begin{cquote}
+\subfloat[Waiting Thread]{\label{f:WaitingThread}\usebox\myboxA}
+\hspace{2\parindentlnth}
+\subfloat[Signalling Thread]{\label{f:SignallingThread}\usebox\myboxB}
+\hspace{2\parindentlnth}
+\subfloat[Other Waiting Thread]{\label{f:SignallingThread}\usebox\myboxC}
+\end{cquote}
+\caption{Barging Prevention}
+\label{f:BargingPrevention}
 \end{figure}
 
-The complexity begins at code sections 4 and 8 in listing \ref{f:int-bulk-cfa}, which are where the existing semantics of internal scheduling needs to be extended for multiple monitors.
-The root of the problem is that bulk acquire is used in a context where one of the monitors is already acquired, which is why it is important to define the behaviour of the previous cfa-code.
-When the signaller thread reaches the location where it should ``release @A & B@'' (listing \ref{f:int-bulk-cfa} line \ref{line:releaseFirst}), it must actually transfer ownership of monitor @B@ to the waiting thread.
-This ownership transfer is required in order to prevent barging into @B@ by another thread, since both the signalling and signalled threads still need monitor @A@.
-There are three options:
-
-\subsubsection{Delaying Signals}
 The obvious solution to the problem of multi-monitor scheduling is to keep ownership of all locks until the last lock is ready to be transferred.
 It can be argued that that moment is when the last lock is no longer needed, because this semantics fits most closely to the behaviour of single-monitor scheduling.
@@ -1792,4 +1664,5 @@
 Depending on the order of signals (listing \ref{f:dependency} line \ref{line:signal-ab} and \ref{line:signal-a}) two cases can happen:
 
+\begin{comment}
 \paragraph{Case 1: thread $\alpha$ goes first.} In this case, the problem is that monitor @A@ needs to be passed to thread $\beta$ when thread $\alpha$ is done with it.
 \paragraph{Case 2: thread $\beta$ goes first.} In this case, the problem is that monitor @B@ needs to be retained and passed to thread $\alpha$ along with monitor @A@, which can be done directly or possibly using thread $\beta$ as an intermediate.
@@ -1801,6 +1674,6 @@
 In both cases, the threads need to be able to distinguish, on a per monitor basis, which ones need to be released and which ones need to be transferred, which means knowing when to release a group becomes complex and inefficient (see next section) and therefore effectively precludes this approach.
 
+
 \subsubsection{Dependency graphs}
-
 
 \begin{figure}
@@ -1881,4 +1754,6 @@
 
 \subsubsection{Partial Signalling} \label{partial-sig}
+\end{comment}
+
 Finally, the solution that is chosen for \CFA is to use partial signalling.
 Again using listing \ref{f:int-bulk-cfa}, the partial signalling solution transfers ownership of monitor @B@ at lines \ref{line:signal1} to the waiter but does not wake the waiting thread since it is still using monitor @A@.
@@ -1895,81 +1770,70 @@
 \end{itemize}
 
-% ======================================================================
-% ======================================================================
+
 \subsection{Signalling: Now or Later}
-% ======================================================================
-% ======================================================================
-\begin{table}
-\begin{tabular}{|c|c|}
-@signal@ & @signal_block@ \\
-\hline
-\begin{cfa}[tabsize=3]
-monitor DatingService {
-	// compatibility codes
-	enum{ CCodes = 20 };
-
-	int girlPhoneNo
-	int boyPhoneNo;
+
+\begin{figure}
+\centering
+\newbox\myboxA
+\begin{lrbox}{\myboxA}
+\begin{cfa}[aboveskip=0pt,belowskip=0pt]
+enum { CCodes = 20 };
+monitor DS {
+	int GirlPhNo, BoyPhNo;
+	condition Girls[CCodes], Boys[CCodes];
+	condition exchange;
 };
-
-condition girls[CCodes];
-condition boys [CCodes];
-condition exchange;
-
-int girl(int phoneNo, int cfa) {
-	// no compatible boy ?
-	if(empty(boys[cfa])) {
-		wait(girls[cfa]);		// wait for boy
-		girlPhoneNo = phoneNo;		// make phone number available
-		signal(exchange);		// wake boy from chair
+int girl( DS & mutex ds, int phNo, int ccode ) {
+	if ( is_empty( Boys[ccode] ) ) {
+		wait( Girls[ccode] );
+		GirlPhNo = phNo;
+		exchange.signal();
 	} else {
-		girlPhoneNo = phoneNo;		// make phone number available
-		signal(boys[cfa]);		// wake boy
-		wait(exchange);		// sit in chair
-	}
-	return boyPhoneNo;
-}
-int boy(int phoneNo, int cfa) {
-	// same as above
-	// with boy/girl interchanged
-}
-\end{cfa}&\begin{cfa}[tabsize=3]
-monitor DatingService {
-
-	enum{ CCodes = 20 }; 	// compatibility codes
-
-	int girlPhoneNo;
-	int boyPhoneNo;
+		GirlPhNo = phNo;
+		signal( Boys[ccode] );
+		exchange.wait();
+	} // if
+	return BoyPhNo;
+}
+int boy( DS & mutex ds, int phNo, int ccode ) {
+	// as above with boy/girl interchanged
+}
+\end{cfa}
+\end{lrbox}
+
+\newbox\myboxB
+\begin{lrbox}{\myboxB}
+\begin{cfa}[aboveskip=0pt,belowskip=0pt]
+
+monitor DS {
+	int GirlPhNo, BoyPhNo;
+	condition Girls[CCodes], Boys[CCodes];
+
 };
-
-condition girls[CCodes];
-condition boys [CCodes];
-// exchange is not needed
-
-int girl(int phoneNo, int cfa) {
-	// no compatible boy ?
-	if(empty(boys[cfa])) {
-		wait(girls[cfa]);		// wait for boy
-		girlPhoneNo = phoneNo;		// make phone number available
-		signal(exchange);		// wake boy from chair
+int girl( DS & mutex ds, int phNo, int ccode ) {
+	if ( is_empty( Boys[ccode] ) ) { // no compatible
+		wait( Girls[ccode] ); // wait for boy
+		GirlPhNo = phNo; // make phone number available
+
 	} else {
-		girlPhoneNo = phoneNo;		// make phone number available
-		signal_block(boys[cfa]); 		// wake boy
-
-		// second handshake unnecessary
-
-	}
-	return boyPhoneNo;
-}
-
-int boy(int phoneNo, int cfa) {
-	// same as above
-	// with boy/girl interchanged
-}
-\end{cfa}
-\end{tabular}
-\caption{Dating service example using \protect\lstinline|signal| and \protect\lstinline|signal_block|. }
-\label{tbl:datingservice}
-\end{table}
+		GirlPhNo = phNo; // make phone number available
+		signal_block( Boys[ccode] ); // restart boy
+
+	} // if
+	return BoyPhNo;
+}
+int boy( DS & mutex ds, int phNo, int ccode ) {
+	// as above with boy/girl interchanged
+}
+\end{cfa}
+\end{lrbox}
+
+\subfloat[\lstinline@signal@]{\label{f:DatingSignal}\usebox\myboxA}
+\qquad
+\subfloat[\lstinline@signal_block@]{\label{f:DatingSignalBlock}\usebox\myboxB}
+\caption{Dating service. }
+\label{f:Dating service}
+\end{figure}
+
 An important note is that, until now, signalling a monitor was a delayed operation.
 The ownership of the monitor is transferred only when the monitor would have otherwise been released, not at the point of the @signal@ statement.
@@ -1988,4 +1852,6 @@
 % ======================================================================
 An alternative to internal scheduling is external scheduling (see Table~\ref{tbl:sched}).
+
+\begin{comment}
 \begin{table}
 \begin{tabular}{|c|c|c|}
@@ -2051,4 +1917,6 @@
 \label{tbl:sched}
 \end{table}
+\end{comment}
+
 This method is more constrained and explicit, which helps users reduce the non-deterministic nature of concurrency.
 Indeed, as the following examples demonstrate, external scheduling allows users to wait for events from other threads without the concern of unrelated events occurring.
