Ignore:
File:
1 edited

Legend:

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

    r3364962 rfb31cb8  
    328328
    329329\begin{cfacode}
    330         thread foo {};
     330thread foo {};
    331331\end{cfacode}
    332332
     
    343343Obviously, for this thread implementation to be usefull it must run some user code. Several other threading interfaces use a function-pointer representation as the interface of threads (for example \Csharp~\cite{Csharp} and Scala~\cite{Scala}). However, this proposal considers that statically tying a \code{main} routine to a thread superseeds this approach. Since the \code{main} routine is already a special routine in \CFA (where the program begins), it is a natural extension of the semantics using overloading to declare mains for different threads (the normal main being the main of the initial thread). As such the \code{main} routine of a thread can be defined as
    344344\begin{cfacode}
    345         thread foo {};
    346 
    347         void main(foo & this) {
    348                 sout | "Hello World!" | endl;
    349         }
     345thread foo {};
     346
     347void main(foo & this) {
     348        sout | "Hello World!" | endl;
     349}
    350350\end{cfacode}
    351351
    352352In this example, threads of type \code{foo} start execution in the \code{void main(foo &)} routine, which prints \code{"Hello World!"}. While this thesis encourages this approach to enforce strongly-typed programming, users may prefer to use the routine-based thread semantics for the sake of simplicity. With these semantics it is trivial to write a thread type that takes a function pointer as a parameter and executes it on its stack asynchronously
    353353\begin{cfacode}
    354         typedef void (*voidFunc)(int);
    355 
    356         thread FuncRunner {
    357                 voidFunc func;
    358                 int arg;
    359         };
    360 
    361         void ?{}(FuncRunner & this, voidFunc inFunc, int arg) {
    362                 this.func = inFunc;
    363         }
    364 
    365         void main(FuncRunner & this) {
    366                 this.func( this.arg );
    367         }
     354typedef void (*voidFunc)(int);
     355
     356thread FuncRunner {
     357        voidFunc func;
     358        int arg;
     359};
     360
     361void ?{}(FuncRunner & this, voidFunc inFunc, int arg) {
     362        this.func = inFunc;
     363}
     364
     365void main(FuncRunner & this) {
     366        this.func( this.arg );
     367}
    368368\end{cfacode}
    369369
Note: See TracChangeset for help on using the changeset viewer.