Ignore:
Timestamp:
Apr 4, 2023, 10:12:57 PM (15 months ago)
Author:
Mike Brooks <mlbrooks@…>
Branches:
ADT, ast-experimental, master
Children:
9bb8ee42
Parents:
ff71057 (diff), bb7422a (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/theses/colby_parsons_MMAth/text/CFA_concurrency.tex

    rff71057 re02e13f  
    11\chapter{Concurrency in \CFA}\label{s:cfa_concurrency}
    22
    3 The groundwork for concurrency in \CFA was laid by Thierry Delisle in his Master's Thesis\cite{Delisle18}.
    4 In that work he introduced coroutines, user level threading, and monitors.
    5 Not listed in that work were the other concurrency features that were needed as building blocks, such as locks, futures, and condition variables which he also added to \CFA.
     3The groundwork for concurrency in \CFA was laid by Thierry Delisle in his Master's Thesis~\cite{Delisle18}.
     4In that work, he introduced generators, coroutines, monitors, and user-level threading.
     5Not listed in that work were basic concurrency features needed as building blocks, such as locks, futures, and condition variables, which he also added to \CFA.
    66
    77\section{Threading Model}\label{s:threading}
    8 \CFA has user level threading and supports a $M:N$ threading model where $M$ user threads are scheduled on $N$ cores, where both $M$ and $N$ can be explicitly set by the user.
    9 Cores are used by a program by creating instances of a \code{processor} struct.
    10 User threads types are defined using the \code{thread} keyword, in the place where a \code{struct} keyword is typically used.
    11 For each thread type a corresponding main must be defined, which is where the thread starts running once it is created.
    12 Listing~\ref{l:cfa_thd_init} shows an example of processor and thread creation.
    13 When processors are added, they are added alongside the existing processor given to each program.
    14 Thus if you want $N$ processors you need to allocate $N-1$.
    15 To join a thread the thread must be deallocated, either deleted if it is allocated on the heap, or go out of scope if stack allocated.
    16 The thread performing the deallocation will wait for the thread being deallocated to terminate before the deallocation can occur.
    17 A thread terminates by returning from the main routine where it starts.
     8\CFA provides user-level threading and supports an $M$:$N$ threading model where $M$ user threads are scheduled on $N$ kernel threads, where both $M$ and $N$ can be explicitly set by the user.
     9Kernel threads are created by instancing a @processor@ structure.
     10User-thread types are defined by creating a @thread@ aggregate-type, \ie replace @struct@ with @thread@.
     11For each thread type a corresponding @main@ routine must be defined, which is where the thread starts running once it is created.
     12Examples of \CFA  user thread and processor creation are shown in \VRef[Listing]{l:cfa_thd_init}.
    1813
    19 \begin{cfacode}[tabsize=3,caption={\CFA user thread and processor creation},label={l:cfa_thd_init}]
    20 
    21 thread my_thread {}     // user thread type
    22 void main( my_thread & this ) { // thread start routine
    23     printf("Hello threading world\n");
     14\begin{cfa}[caption={Example of \CFA user thread and processor creation},label={l:cfa_thd_init}]
     15@thread@ my_thread {...};                       $\C{// user thread type}$
     16void @main@( my_thread & this ) {       $\C{// thread start routine}$
     17        sout | "Hello threading world";
    2418}
    2519
    2620int main() {
    27     // add 2 processors, now 3 total
    28     processor p[2];   
    29     {
    30         my_thread t1;
    31         my_thread t2;
    32     } // waits for threads to end before going out of scope
     21        @processor@ p[2];                               $\C{// add 2 processors = 3 total with starting processor}$
     22        {
     23                my_thread t[2], * t3 = new();   $\C{// create 3 user threads, running in main routine}$
     24                ... // execute concurrently
     25                delete( t3 );                           $\C{// wait for thread to end and deallocate}$
     26        } // wait for threads to end and deallocate
    3327}
     28\end{cfa}
    3429
    35 \end{cfacode}
     30When processors are added, they are added alongside the existing processor given to each program.
     31Thus, for $N$ processors, allocate $N-1$ processors.
     32A thread is implicitly joined at deallocated, either implicitly at block exit for stack allocation or explicitly at @delete@ for heap allocation.
     33The thread performing the deallocation must wait for the thread to terminate before the deallocation can occur.
     34A thread terminates by returning from the main routine where it starts.
     35
     36% Local Variables: %
     37% tab-width: 4 %
     38% End: %
Note: See TracChangeset for help on using the changeset viewer.