Ignore:
File:
1 edited

Legend:

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

    rcf966b5 r20ffcf3  
    77
    88\section{Threads as monitors}
    9 As 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}]
     9As 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}
    1211// Visualization declaration
    1312thread Renderer {} renderer;
     
    2120void draw( Renderer & mutex this, Frame * frame );
    2221
    23 // Simulation loop
     22// Simualation loop
    2423void main( Simulator & this ) {
    2524        while( true ) {
     
    3736}
    3837\end{cfacode}
    39 \end{figure}
    4038One 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 :
    41 \begin{figure}[H]
    42 \begin{cfacode}[caption={Same toy simulator with proper termination condition.},label={lst:engine-v2}]
     39\begin{cfacode}
    4340// Visualization declaration
    4441thread Renderer {} renderer;
     
    5249void draw( Renderer & mutex this, Frame * frame );
    5350
    54 // Simulation loop
     51// Simualation loop
    5552void main( Simulator & this ) {
    5653        while( true ) {
     
    7976// Call destructor for renderer to signify shutdown
    8077\end{cfacode}
    81 \end{figure}
    8278
    8379\section{Fibers \& Threads}
    84 As 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~:
     80As 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~:
    8581\begin{cfacode}
    8682unsigned int default_preemption() {
     
    8884}
    8985\end{cfacode}
    90 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 \glspl{uthread} in the same system, as in listing \ref{lst:fiber-uthread}
     86This 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 :
    9187\begin{figure}
    92 \begin{cfacode}[caption={Using fibers and \glspl{uthread} side-by-side in \CFA},label={lst:fiber-uthread}]
     88\begin{cfacode}
    9389//Cluster forward declaration
    9490struct cluster;
Note: See TracChangeset for help on using the changeset viewer.