Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/proposals/concurrency/text/together.tex

    r20ffcf3 rcf966b5  
    77
    88\section{Threads as monitors}
    9 As it was subtely alluded in section \ref{threads}, \code{threads} in \CFA are in fact monitors, which means that all monitor features are available when using threads. For example, here is a very simple two thread pipeline that could be used for a simulator of a game engine :
    10 \begin{cfacode}
     9As it was subtly alluded in section \ref{threads}, \code{thread}s in \CFA are in fact monitors, which means that all monitor features are available when using threads. For example, here is a very simple two thread pipeline that could be used for a simulator of a game engine :
     10\begin{figure}[H]
     11\begin{cfacode}[caption={Toy simulator using \code{thread}s and \code{monitor}s.},label={lst:engine-v1}]
    1112// Visualization declaration
    1213thread Renderer {} renderer;
     
    2021void draw( Renderer & mutex this, Frame * frame );
    2122
    22 // Simualation loop
     23// Simulation loop
    2324void main( Simulator & this ) {
    2425        while( true ) {
     
    3637}
    3738\end{cfacode}
     39\end{figure}
    3840One of the obvious complaints of the previous code snippet (other than its toy-like simplicity) is that it does not handle exit conditions and just goes on forever. Luckily, the monitor semantics can also be used to clearly enforce a shutdown order in a concise manner :
    39 \begin{cfacode}
     41\begin{figure}[H]
     42\begin{cfacode}[caption={Same toy simulator with proper termination condition.},label={lst:engine-v2}]
    4043// Visualization declaration
    4144thread Renderer {} renderer;
     
    4952void draw( Renderer & mutex this, Frame * frame );
    5053
    51 // Simualation loop
     54// Simulation loop
    5255void main( Simulator & this ) {
    5356        while( true ) {
     
    7679// Call destructor for renderer to signify shutdown
    7780\end{cfacode}
     81\end{figure}
    7882
    7983\section{Fibers \& Threads}
    80 As mentionned in section \ref{preemption}, \CFA uses preemptive threads by default but can use fibers on demand. Currently, using fibers is done by adding the following line of code to the program~:
     84As mentioned in section \ref{preemption}, \CFA uses preemptive threads by default but can use fibers on demand. Currently, using fibers is done by adding the following line of code to the program~:
    8185\begin{cfacode}
    8286unsigned int default_preemption() {
     
    8488}
    8589\end{cfacode}
    86 This function is called by the kernel to fetch the default preemption rate, where 0 signifies an infinite time-slice i.e. no preemption. However, once clusters are fully implemented, it will be possible to create fibers and uthreads in on the same system :
     90This function is called by the kernel to fetch the default preemption rate, where 0 signifies an infinite time-slice, i.e., no preemption. However, once clusters are fully implemented, it will be possible to create fibers and \glspl{uthread} in the same system, as in listing \ref{lst:fiber-uthread}
    8791\begin{figure}
    88 \begin{cfacode}
     92\begin{cfacode}[caption={Using fibers and \glspl{uthread} side-by-side in \CFA},label={lst:fiber-uthread}]
    8993//Cluster forward declaration
    9094struct cluster;
Note: See TracChangeset for help on using the changeset viewer.