- File:
-
- 1 edited
-
doc/proposals/concurrency/text/together.tex (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
doc/proposals/concurrency/text/together.tex
rcf966b5 r20ffcf3 7 7 8 8 \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}] 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} 12 11 // Visualization declaration 13 12 thread Renderer {} renderer; … … 21 20 void draw( Renderer & mutex this, Frame * frame ); 22 21 23 // Simu lation loop22 // Simualation loop 24 23 void main( Simulator & this ) { 25 24 while( true ) { … … 37 36 } 38 37 \end{cfacode} 39 \end{figure}40 38 One 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} 43 40 // Visualization declaration 44 41 thread Renderer {} renderer; … … 52 49 void draw( Renderer & mutex this, Frame * frame ); 53 50 54 // Simu lation loop51 // Simualation loop 55 52 void main( Simulator & this ) { 56 53 while( true ) { … … 79 76 // Call destructor for renderer to signify shutdown 80 77 \end{cfacode} 81 \end{figure}82 78 83 79 \section{Fibers \& Threads} 84 As mention ed 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~: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~: 85 81 \begin{cfacode} 86 82 unsigned int default_preemption() { … … 88 84 } 89 85 \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}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 : 91 87 \begin{figure} 92 \begin{cfacode} [caption={Using fibers and \glspl{uthread} side-by-side in \CFA},label={lst:fiber-uthread}]88 \begin{cfacode} 93 89 //Cluster forward declaration 94 90 struct cluster;
Note:
See TracChangeset
for help on using the changeset viewer.