Ignore:
Timestamp:
Oct 17, 2017, 12:06:15 PM (7 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
633c711
Parents:
0aaac0e
Message:

Updated thesis up to implementation

File:
1 edited

Legend:

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

    r0aaac0e 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.