Changes in / [2295320:2ae845e9]


Ignore:
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • doc/bibliography/pl.bib

    r2295320 r2ae845e9  
    36853685    address     = {Waterloo, Ontario, Canada, N2L 3G1},
    36863686    note        = {\url{http://uwspace.uwaterloo.ca/bitstream/10012/3501/1/Thesis.pdf}},
    3687 }
    3688 
    3689 @article{Hesselink24,
    3690     author      = {Wim A. Hesselink and Peter A. Buhr and Colby A. Parsons},
    3691     title       = {First-Come-First-Served as a Separate Principle},
    3692     journal     = {ACM Trans. Parallel Comput.},
    3693     publisher   = {ACM},
    3694     address     = {New York, NY, USA},
    3695     volume      = 11,
    3696     number      = 4,
    3697     month       = nov,
    3698     year        = 2024,
    36993687}
    37003688
  • doc/uC++toCFA/uC++toCFA.tex

    r2295320 r2ae845e9  
    1111%% Created On       : Wed Apr  6 14:53:29 2016
    1212%% Last Modified By : Peter A. Buhr
    13 %% Last Modified On : Mon Nov 11 21:51:39 2024
    14 %% Update Count     : 6144
     13%% Last Modified On : Fri Nov  8 08:22:25 2024
     14%% Update Count     : 6107
    1515%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1616
     
    498498
    499499
    500 \section{Coroutine}
     500\section{Coroutines}
    501501
    502502\begin{cquote}
     
    591591
    592592struct StrMsg : @public uActor::Message@ {
    593 
    594593        const char * val; // string message
     594
    595595
    596596        StrMsg( const char * val ) :
     
    600600_Actor Hello { ${\color{red}\LstCommentStyle{// : public uActor}}$
    601601        Allocation receive( Message & msg ) {
    602                 Case( @StartMsg@, msg ) { // discriminate
    603 
    604                 } else Case( StrMsg, msg ) {
     602                Case( StrMsg, msg ) { // discriminate
    605603                        osacquire( cout ) << msg_d->val << endl;
    606 
    607                 } else Case( @StopMsg@, msg )
    608                         return Delete;  // delete actor
    609                 return Nodelete;  // reuse actor
     604                };
     605                return Delete;  // delete after use
    610606        }
    611607};
    612608int main() {
    613609        @uActor::start();@ // start actor system
    614         *new Hello() | uActor::startMsg
    615                 | *new StrMsg( "hello" ) | uActor::stopMsg;
    616         *new Hello() | uActor::startMsg
    617                 | *new StrMsg( "bonjour" ) | uActor::stopMsg;
    618         @uActor::stop();@  // wait for actors to terminate
     610        *new Hello() | *new StrMsg( "hello" );
     611        *new Hello() | *new StrMsg( "bonjour" );
     612        @uActor::stop();@  // wait for all actors to terminate
    619613}
    620614\end{uC++}
     
    629623        const char * val; // string message
    630624};
    631 void ?{}( StrMsg & msg, const char * str ) {
     625void ?{}( StrMsg & msg, char * str ) {
     626        msg.val = str;
    632627        @set_allocation( msg, Delete );@ // delete after use
    633         msg.val = str;
    634 }
    635 struct Hello { @inline actor;@ }; // derived actor
    636 allocation receive( Hello & receiver, @start_msg_t@ & ) {
    637         return Nodelete;
    638 }
     628}
     629struct Hello {
     630        @inline actor;@ // derived actor
     631};
    639632allocation receive( Hello & receiver, StrMsg & msg ) {
    640633        mutex( sout ) sout | msg.val;
    641         return Nodelete;  // reuse actor
    642 }
    643 allocation receive( Hello & receiver, @stop_msg_t@ & ) {
    644         return Delete;  // delete actor
     634        return Delete;  // delete after use
    645635}
    646636
    647637int main() {
    648         @actor_start();@  // start actor system
    649         *(Hello *)new() | start_msg
    650                 | *(StrMsg *)new( "hello" ) | stop_msg;
    651         *(Hello *)new() | start_msg
    652                 | *(StrMsg *)new( "bonjour" ) | stop_msg;
    653         @actor_stop();@  // wait for actors to terminate
    654 }
    655 \end{cfa}
    656 \end{tabular}
    657 \end{cquote}
    658 
    659 
    660 \section{Thread}
     638        @start_actor_system();@  // start actor system
     639        *(Hello *)new() | *(StrMsg *)new( "hello" );
     640        *(Hello *)new() | *(StrMsg *)new( "bonjour" );
     641        @stop_actor_system();@  // wait for all actors to terminate
     642}
     643\end{cfa}
     644\end{tabular}
     645\end{cquote}
     646
     647
     648\section{Threads}
    661649
    662650\begin{cquote}
     
    722710
    723711
    724 \section{Monitor}
     712\section{Monitors}
    725713
    726714Internal Scheduling
     
    788776\end{tabular}
    789777\end{cquote}
    790 
    791 \newpage
    792 
     778\enlargethispage{1000pt}
    793779External Scheduling
    794780\begin{cquote}
  • libcfa/src/concurrency/actor.hfa

    r2295320 r2ae845e9  
    398398// TODO: update globals in this file to be static fields once the static fields project is done
    399399static executor * __actor_executor_ = 0p;
    400 static bool __actor_executor_passed = false;                    // was an executor passed to actor_start
     400static bool __actor_executor_passed = false;                    // was an executor passed to start_actor_system
    401401static size_t __num_actors_ = 0;                                                // number of actor objects in system
    402402static struct thread$ * __actor_executor_thd = 0p;              // used to wake executor after actors finish
     
    410410        // Once an actor is allocated it must be sent a message or the actor system cannot stop. Hence, its receive
    411411        // member must be called to end it
    412         DEBUG_ABORT( __actor_executor_ == 0p, "Creating actor before calling actor_start() can cause undefined behaviour.\n" );
     412        DEBUG_ABORT( __actor_executor_ == 0p, "Creating actor before calling start_actor_system() can cause undefined behaviour.\n" );
    413413        alloc = Nodelete;
    414414        ticket = __get_next_ticket( *__actor_executor_ );
     
    682682}
    683683
    684 static inline void actor_start( size_t num_thds ) {
     684static inline void start_actor_system( size_t num_thds ) {
    685685        __reset_stats();
    686686        __actor_executor_thd = active_thread();
     
    689689}
    690690
    691 static inline void actor_start() { actor_start( get_proc_count( *active_cluster() ) ); }
    692 
    693 static inline void actor_start( executor & this ) {
     691static inline void start_actor_system() { start_actor_system( get_proc_count( *active_cluster() ) ); }
     692
     693static inline void start_actor_system( executor & this ) {
    694694        __reset_stats();
    695695        __actor_executor_thd = active_thread();
     
    698698}
    699699
    700 static inline void actor_stop() {
     700static inline void stop_actor_system() {
    701701        park();                                                                                         // unparked when actor system is finished
    702702
     
    715715struct finished_msg_t { inline message; } finished_msg = __base_msg_finished;
    716716
    717 allocation receive( actor & this, delete_msg_t & ) { return Delete; }
    718 allocation receive( actor & this, destroy_msg_t & ) { return Destroy; }
    719 allocation receive( actor & this, finished_msg_t & ) { return Finished; }
     717allocation receive( actor & this, delete_msg_t & msg ) { return Delete; }
     718allocation receive( actor & this, destroy_msg_t & msg ) { return Destroy; }
     719allocation receive( actor & this, finished_msg_t & msg ) { return Finished; }
    720720
    721721// Default messages used all the time.
    722 struct start_msg_t { inline message; } start_msg = __base_msg_finished; // start actor
    723 struct stop_msg_t { inline message; } stop_msg = __base_msg_finished; // terminate actor
     722//static struct startmsg_t { inline message; } start_msg; // start actor
     723//static struct stopmsg_t { inline message; } stop_msg; // terminate actor
  • libcfa/src/concurrency/barrier.hfa

    r2295320 r2ae845e9  
    1 //                               -*- Mode: C -*-
    2 //
     1//
    32// Cforall Version 1.0.0 Copyright (C) 2022 University of Waterloo
    4 // 
     3//
    54// The contents of this file are covered under the licence agreement in the
    65// file "LICENCE" distributed with Cforall.
    76//
    8 // barrier.hfa -- simple barrier implemented using a monitor
    9 // 
    10 // Author           : Peter A. Buhr
    11 // Created On       : Sun Nov 10 08:07:35 2024
    12 // Last Modified By : Peter A. Buhr
    13 // Last Modified On : Sun Nov 10 08:11:55 2024
    14 // Update Count     : 3
    15 // 
     7// barrier.hfa -- simple barrier implemented from monitors
     8//
     9// Author           : Thierry Delisle
     10// Created On       : Thu Mar 31 16:51:35 2022
     11// Last Modified By :
     12// Last Modified On :
     13// Update Count     :
     14//
    1615
    1716#pragma once
     
    1918#include <monitor.hfa>
    2019
    21 // Plan 9 inheritance does not work with monitors. Two monitor locks are created.
     20// Simple barrier based on a monitor
     21monitor barrier {
     22        // Number of threads blocking needed to unblock the barrier
     23        // Unsigned should be enough, I don't expect use cases with 2^32 thread barriers.
     24        unsigned width;
    2225
    23 monitor barrier {
    24         unsigned int group, arrivals;                                           // group size, arrival counter
    25         condition c;                                                                            // wait for group to form
     26        // Current count (counting backwards)
     27        unsigned count;
     28
     29        // Barrier uses internal scheduling
     30        condition c;
    2631};
    2732
    2833// Constructor
    29 void ?{}( barrier & b, unsigned group ) {
    30         b.group = b.arrivals = group;                                           // count backwards
     34void ?{}( barrier & this, unsigned width ) {
     35        this.width = width;
     36        this.count = width; // Count backwards so initialize at width
    3137}
    3238
    33 // Returns a value indicating the reverse order the threads arrived i.e. last thread returns 0 (and does not block)
    34 // last is an optional hook that is called by the last thread before unblocking the others.
    35 static inline unsigned block( barrier & mutex b, fptr_t last = (fptr_t)0 ) with( b ) {
    36         arrivals -= 1;                                                                          // prefix decrement so last is 0 not 1
    37         unsigned arrived = b.arrivals;                                          // note arrival order
    38         if ( arrivals != 0 ) {                                                          // wait for group to form
    39                 wait( b.c );
    40         } else {                                                                                        // group formed
    41                 if ( last ) last();                                                             // safe to call
    42                 signal_all( c );                                                                // unblock group
    43                 arrivals = group;                                                               // reset
    44         } // if
    45         return arrived;                                                                         // return arrival order
     39// block until the number of threads needed have blocked
     40// returns an value indicating the reverse order the threads arrived in
     41// i.e. last thread will return 0 (and not block)
     42//      second last thread returns 1
     43//      etc.
     44// last is an optional hook that will be called by the last thread
     45// before unblocking the others
     46static inline unsigned block(barrier & mutex this, fptr_t last = (fptr_t)0 ) {
     47        this.count -= 1; // prefix decrement so we the last is 0 and not 1
     48        unsigned arrival = this.count; // Note arrival order
     49        if(arrival == 0) {
     50                if(last) last();
     51                // If arrived last unblock everyone and reset
     52                signal_all(this.c);
     53                this.count = this.width;
     54        } else {
     55                // Otherwise block
     56                wait(this.c);
     57        }
     58        return arrival; // return arrival order
    4659}
  • tests/concurrency/actors/dynamic.cfa

    r2295320 r2ae845e9  
    4848
    4949        executor e{ 0, 1, 1, false };
    50         actor_start( e );
     50        start_actor_system( e );
     51
    5152        sout | "started";
    5253
     
    5758        *d_actor | *d_msg;
    5859
    59         actor_stop();
     60        stop_actor_system();
     61
    6062        sout | "stopped";
    6163}
  • tests/concurrency/actors/executor.cfa

    r2295320 r2ae845e9  
    8484
    8585        sout | "starting";
    86         actor_start( e );
     86
     87        start_actor_system( e );
     88
    8789        sout | "started";
     90
    8891        d_actor actors[ Actors ];
     92
    8993        for ( i; Actors ) {
    9094                actors[i] | shared_msg;
    9195        } // for
     96
    9297        sout | "stopping";
    93         actor_stop();
     98
     99        stop_actor_system();
     100
    94101        sout | "stopped";
    95102}
  • tests/concurrency/actors/inherit.cfa

    r2295320 r2ae845e9  
    2929        sout | "Start";
    3030        {
    31                 actor_start();
     31                start_actor_system();
    3232                D_msg * dm = alloc();
    3333                (*dm){};
     
    4040                *s | *dm;
    4141                *s2 | *dm2;
    42                 actor_stop();
     42                stop_actor_system();
    4343        }
    4444        {
    45                 actor_start();
     45                start_actor_system();
    4646                Server s[2];
    4747                D_msg * dm = alloc();
     
    5151                s[0] | *dm;
    5252                s[1] | *dm2;
    53                 actor_stop();
     53                stop_actor_system();
    5454        }
    5555        sout | "Finished";
  • tests/concurrency/actors/inline.cfa

    r2295320 r2ae845e9  
    3838        processor p;
    3939        {
    40                 actor_start();                                                          // sets up executor
     40                start_actor_system();                                                           // sets up executor
    4141                d_actor da;
    4242                d_msg * dm = alloc();
    4343                (*dm){ 42, 2423 };
    4444                da | *dm;
    45                 actor_stop();                                                           // waits until actors finish
     45                stop_actor_system();                                                            // waits until actors finish
    4646        }
    4747        {
    48                 actor_start();                                                          // sets up executor
     48                start_actor_system();                                                           // sets up executor
    4949                d_actor da;
    5050                d_msg2 dm{ 29079 };
     
    5454                virtual_dtor * v = &dm;
    5555                da | dm;
    56                 actor_stop();                                                           // waits until actors finish
     56                stop_actor_system();                                                            // waits until actors finish
    5757        }
    5858}
  • tests/concurrency/actors/matrixMultiply.cfa

    r2295320 r2ae845e9  
    8888
    8989        sout | "starting";
    90         actor_start( e );
     90
     91        start_actor_system( e );
     92
    9193        sout | "started";
     94
    9295        derived_msg messages[xr];
     96
    9397        derived_actor actors[xr];
    9498
     
    96100                messages[r]{ Z[r], X[r], Y };
    97101        } // for
     102
    98103        for ( r; xr ) {
    99104                actors[r] | messages[r];
     
    101106
    102107        sout | "stopping";
    103         actor_stop();
     108
     109        stop_actor_system();
     110
    104111        sout | "stopped";
    105112
  • tests/concurrency/actors/pingpong.cfa

    r2295320 r2ae845e9  
    4747        processor p[Processors - 1];
    4848
    49         actor_start( Processors ); // test passing number of processors
     49        start_actor_system( Processors ); // test passing number of processors
    5050        ping pi_actor;
    5151        pong po_actor;
     
    5454        p_msg m;
    5555        pi_actor | m;
    56         actor_stop();
     56        stop_actor_system();
    5757
    5858        sout | "end";
  • tests/concurrency/actors/poison.cfa

    r2295320 r2ae845e9  
    1515        sout | "Finished";
    1616        {
    17                 actor_start();
     17                start_actor_system();
    1818                Server s[10];
    1919                for ( i; 10 ) {
    2020                        s[i] | finished_msg;
    2121                }
    22                 actor_stop();
     22                stop_actor_system();
    2323        }
    2424
    2525        sout | "Delete";
    2626        {
    27                 actor_start();
     27                start_actor_system();
    2828                for ( i; 10 ) {
    2929                        Server * s = alloc();
     
    3131                        (*s) | delete_msg;
    3232                }
    33                 actor_stop();
     33                stop_actor_system();
    3434        }
    3535
    3636        sout | "Destroy";
    3737        {
    38                 actor_start();
     38                start_actor_system();
    3939                Server s[10];
    4040                for ( i; 10 )
    4141                        s[i] | destroy_msg;
    42                 actor_stop();
     42                stop_actor_system();
    4343                for ( i; 10 )
    4444                        if (s[i].val != 777)
  • tests/concurrency/actors/static.cfa

    r2295320 r2ae845e9  
    4545
    4646        executor e{ 0, 1, 1, false };
    47         actor_start( e );
     47        start_actor_system( e );
     48
    4849        sout | "started";
     50
    4951        derived_msg msg;
     52
    5053        derived_actor actor;
     54
    5155        actor | msg;
    52         actor_stop();
     56
     57        stop_actor_system();
     58
    5359        sout | "stopped";
    5460}
  • tests/concurrency/actors/types.cfa

    r2295320 r2ae845e9  
    6767
    6868        sout | "basic test";
    69         actor_start( Processors ); // test passing number of processors
     69        start_actor_system( Processors ); // test passing number of processors
    7070        derived_actor a;
    7171        d_msg b, c;
     
    7373        c.num = 2;
    7474        a | b | c;
    75         actor_stop();
     75        stop_actor_system();
    7676
    7777        sout | "same message and different actors test";
    78         actor_start(); // let system detect # of processors
     78        start_actor_system(); // let system detect # of processors
    7979        derived_actor2 d_ac2_0, d_ac2_1;
    8080        d_msg d_ac2_msg;
     
    8282        d_ac2_0 | d_ac2_msg;
    8383        d_ac2_1 | d_ac2_msg;
    84         actor_stop();
     84        stop_actor_system();
    8585
    8686       
     
    8888                sout | "same message and different actor types test";
    8989                executor e{ 0, Processors, Processors == 1 ? 1 : Processors * 4, false };
    90                 actor_start( e ); // pass an explicit executor
     90                start_actor_system( e ); // pass an explicit executor
    9191                derived_actor2 d_ac2_2;
    9292                derived_actor3 d_ac3_0;
     
    9595                d_ac3_0 | d_ac23_msg;
    9696                d_ac2_2 | d_ac23_msg;
    97                 actor_stop();
     97                stop_actor_system();
    9898        } // RAII to clean up executor
    9999
     
    101101                sout | "different message types, one actor test";
    102102                executor e{ 1, Processors, Processors == 1 ? 1 : Processors * 4, true };
    103                 actor_start( Processors );
     103                start_actor_system( Processors );
    104104                derived_actor3 a3;
    105105                d_msg b1;
     
    108108                c2.num = 5;
    109109                a3 | b1 | c2;
    110                 actor_stop();
     110                stop_actor_system();
    111111        } // RAII to clean up executor
    112112
     
    114114                sout | "nested inheritance actor test";
    115115                executor e{ 1, Processors, Processors == 1 ? 1 : Processors * 4, true };
    116                 actor_start( Processors );
     116                start_actor_system( Processors );
    117117                derived_actor4 a4;
    118118                d_msg b1;
     
    121121                c2.num = 5;
    122122                a4 | b1 | c2;
    123                 actor_stop();
     123                stop_actor_system();
    124124        } // RAII to clean up executor
    125125
  • tests/concurrency/barrier/order.cfa

    r2295320 r2ae845e9  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // order.cfa -- validates barrier return value from barrier block
     7// order.cfa -- validates barriers the return value of
     8//                                 barrier block
    89//
    910// Author           : Thierry Delisle
    1011// Created On       : Fri Apr 01 11:39:09 2022
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Nov 10 11:22:56 2024
    13 // Update Count     : 20
     12// Last Modified By :
     13// Last Modified On :
     14// Update Count     :
    1415//
     16
     17// Test validates barrier and block return value by checking
     18// that no more than one thread gets the same return value
    1519
    1620#include <concurrency/barrier.hfa>
     
    1923#include <thread.hfa>
    2024
    21 enum { NUM_LAPS = 173, NUM_THREADS = 11 };
     25const unsigned NUM_LAPS = 173;
     26const unsigned NUM_THREADS = 11;
    2227
     28// The barrier we are testing
    2329barrier bar = { NUM_THREADS };
    2430
    25 volatile unsigned generation = 0;                                               // count laps
    26 void last() {
    27         generation += 1;                                                                        // last thread at barrier advances
    28 }
    29 volatile unsigned * generations;                                                // global array pointer
     31// The return values of the previous generation.
     32volatile unsigned * generation;
    3033
    3134thread Tester {};
    3235void main( Tester & this ) {
    33         for ( l; NUM_LAPS ) {
    34                 yield( prng( this, 10 ) );                                              // yield for chaos
    35                 unsigned int order = block( bar, last );                // block at barrier
     36        // Repeat a few times
     37        for(l; NUM_LAPS) {
     38                // Yield for chaos
     39                yield( prng(this, 10) );
    3640
    37                 // For G == T, no thread should be able to advance generation until current generation finishes.
    38                 if ( generation - 1 != l || generations[order] != l ) { // generation advanced in block
    39                         mutex( sout ) sout | "mismatched generation, expected" | l | "got" | generation;
    40                 } // if
    41                 generations[order] = l + 1;                                             // every thread advances their current order generation
    42         } // for
     41                // Block and what order we arrived
     42                unsigned ret = block(bar);
     43
     44                // Check what was the last generation of that last thread in this position
     45                unsigned g = generation[ret];
     46
     47                // Is it what we expect?
     48                if(g != l) {
     49                        // Complain that they are different
     50                        sout | "Gen" | l | ": Expeced generation at" | ret | "to be" | l | "was" | g;
     51                }
     52
     53                // Mark the expected next generation
     54                generation[ret] = l+1;
     55        }
    4356}
    4457
    4558int main() {
     59        // Create the data ans zero it.
    4660        volatile unsigned gen_data[NUM_THREADS];
    47         for( t; NUM_THREADS ) gen_data[t] = 0;
    48         generations = gen_data;                                                         // global points at local
     61        for(t; NUM_THREADS)
     62                gen_data[t] = 0;
    4963
    50         processor p[4];                                                                         // parallelism
    51         {                                                                                                       // run experiment
     64        generation = gen_data;
     65
     66        // Run the experiment
     67        processor p[4];
     68        {
    5269                Tester testers[NUM_THREADS];
    5370        }
Note: See TracChangeset for help on using the changeset viewer.