- File:
-
- 1 edited
-
doc/proposals/concurrency/text/together.tex (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
doc/proposals/concurrency/text/together.tex
r20ffcf3 r3364962 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 monitorfeatures 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 :9 As it was subtely alluded in section \ref{threads}, \code{threads} in \CFA are in fact monitors. This means that all the monitors 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 10 \begin{cfacode} 11 11 // Visualization declaration … … 36 36 } 37 37 \end{cfacode} 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 for ever. Luckily, the monitor semantics can also be used to clearly enforce a shutdown order in a concise manner :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 for ever. Luckily, the monitor semantics can also be used to clearly enforce a shutdown order in a concise manner : 39 39 \begin{cfacode} 40 40 // Visualization declaration … … 72 72 } 73 73 } 74 75 // Call destructor for simulator once simulator finishes76 // Call destructor for renderer to signify shutdown77 74 \end{cfacode} 78 75 79 76 \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~:81 \begin{cfacode}82 unsigned int default_preemption() {83 return 0;84 }85 \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 :87 \begin{figure}88 \begin{cfacode}89 //Cluster forward declaration90 struct cluster;91 92 //Processor forward declaration93 struct processor;94 95 //Construct clusters with a preemption rate96 void ?{}(cluster& this, unsigned int rate);97 //Construct processor and add it to cluster98 void ?{}(processor& this, cluster& cluster);99 //Construct thread and schedule it on cluster100 void ?{}(thread& this, cluster& cluster);101 102 //Declare two clusters103 cluster thread_cluster = { 10`ms }; //Preempt every 10 ms104 cluster fibers_cluster = { 0 }; //Never preempt105 106 //Construct 4 processors107 processor processors[4] = {108 //2 for the thread cluster109 thread_cluster;110 thread_cluster;111 //2 for the fibers cluster112 fibers_cluster;113 fibers_cluster;114 };115 116 //Declares thread117 thread UThread {};118 void ?{}(UThread& this) {119 //Construct underlying thread to automatically120 //be scheduled on the thread cluster121 (this){ thread_cluster }122 }123 124 void main(UThread & this);125 126 //Declares fibers127 thread Fiber {};128 void ?{}(Fiber& this) {129 //Construct underlying thread to automatically130 //be scheduled on the fiber cluster131 (this.__thread){ fibers_cluster }132 }133 134 void main(Fiber & this);135 \end{cfacode}136 \end{figure}
Note:
See TracChangeset
for help on using the changeset viewer.