Changeset fb31cb8 for doc/proposals/concurrency/text/basics.tex
- Timestamp:
- Oct 17, 2017, 12:06:15 PM (7 years ago)
- 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
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/proposals/concurrency/text/basics.tex
r0aaac0e rfb31cb8 328 328 329 329 \begin{cfacode} 330 330 thread foo {}; 331 331 \end{cfacode} 332 332 … … 343 343 Obviously, 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 344 344 \begin{cfacode} 345 346 347 348 349 345 thread foo {}; 346 347 void main(foo & this) { 348 sout | "Hello World!" | endl; 349 } 350 350 \end{cfacode} 351 351 352 352 In 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 353 353 \begin{cfacode} 354 355 356 357 358 359 360 361 362 363 364 365 366 367 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 } 368 368 \end{cfacode} 369 369
Note: See TracChangeset
for help on using the changeset viewer.