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