Changeset 5407cdc for tests/concurrent


Ignore:
Timestamp:
Apr 28, 2021, 4:56:50 PM (5 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum, stuck-waitfor-destruct
Children:
8d66610
Parents:
feacef9 (diff), b7fd2db6 (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

Location:
tests/concurrent
Files:
6 added
3 edited

Legend:

Unmodified
Added
Removed
  • tests/concurrent/clib.c

    rfeacef9 r5407cdc  
    1 #include <clib/cfathread.h>
    2 
    31#include <stdio.h>
    42#include <stdlib.h>
     3#include <clib/cfathread.h>
     4#include <bits/defs.hfa>
     5
     6extern "C" {
     7void _exit(int status);
     8}
    59
    610thread_local struct drand48_data buffer = { 0 };
     
    1519cfathread_t volatile blocked[blocked_size];
    1620
    17 void Worker( cfathread_t this ) {
     21void * Worker( void * ) {
    1822        for(int i = 0; i < 1000; i++) {
    1923                int idx = myrand() % blocked_size;
     
    2226                        cfathread_unpark( thrd );
    2327                } else {
    24                         cfathread_t thrd = __atomic_exchange_n(&blocked[idx], this, __ATOMIC_SEQ_CST);
     28                        cfathread_t thrd = __atomic_exchange_n(&blocked[idx], cfathread_self(), __ATOMIC_SEQ_CST);
    2529                        cfathread_unpark( thrd );
    2630                        cfathread_park();
     
    2832        }
    2933        printf("Done\n");
     34        return NULL;
    3035}
    3136
    3237volatile bool stop;
    33 void Unparker( cfathread_t this ) {
     38void * Unparker( void * ) {
    3439        while(!stop) {
    3540                int idx = myrand() % blocked_size;
     
    4247        }
    4348        printf("Done Unparker\n");
     49        return NULL;
    4450}
    4551
     
    5157        }
    5258
    53         cfathread_setproccnt( 4 );
    54         cfathread_t u = cfathread_create( Unparker );
     59        cfathread_cluster_t cl = cfathread_cluster_self();
     60
     61        cfathread_cluster_add_worker( cl, NULL, NULL, NULL );
     62        cfathread_cluster_add_worker( cl, NULL, NULL, NULL );
     63        cfathread_cluster_add_worker( cl, NULL, NULL, NULL );
     64
     65        cfathread_attr_t attr;
     66        cfathread_attr_init(&attr);
     67        cfathread_attr_setcluster(&attr, cl);
     68
     69        cfathread_t u;
     70        cfathread_create( &u, &attr, Unparker, NULL );
    5571        {
    5672                cfathread_t t[20];
    5773                for(int i = 0; i < 20; i++) {
    58                         t[i] = cfathread_create( Worker );
     74                        cfathread_create( &t[i], &attr, Worker, NULL );
    5975                }
    6076                for(int i = 0; i < 20; i++) {
    61                         cfathread_join( t[i] );
     77                        cfathread_join( t[i], NULL );
    6278                }
    6379        }
    6480        stop = true;
    65         cfathread_join(u);
    66         cfathread_setproccnt( 1 );
     81        cfathread_join(u, NULL);
     82        cfathread_attr_destroy(&attr);
     83        fflush(stdout);
     84        _exit(0);
    6785}
  • tests/concurrent/coroutineYield.cfa

    rfeacef9 r5407cdc  
    3838
    3939
     40Coroutine c;
    4041int main(int argc, char* argv[]) {
    41         Coroutine c;
    4242        for(int i = 0; TEST(i < N); i++) {
    4343                #if !defined(TEST_FOREVER)
  • tests/concurrent/futures/multi.cfa

    rfeacef9 r5407cdc  
    55
    66thread Server {
    7         int cnt, iteration;
     7        int pending, done, iteration;
    88        multi_future(int) * request;
    99};
    1010
    1111void ?{}( Server & this ) {
    12         this.cnt = 0;
     12        ((thread&)this){"Server Thread"};
     13        this.pending = 0;
     14        this.done = 0;
    1315        this.iteration = 0;
    1416        this.request = 0p;
     
    1618
    1719void ^?{}( Server & mutex this ) {
    18         assert(this.cnt == 0);
    19     this.request = 0p;
     20        assert(this.pending == 0);
     21        this.request = 0p;
    2022}
    2123
     
    2426}
    2527
    26 void process( Server & mutex this ) {
    27         fulfil( *this.request, this.iteration );
    28         this.iteration++;
     28void call( Server & mutex this ) {
     29        this.pending++;
    2930}
    3031
    31 void call( Server & mutex this ) {
    32         this.cnt++;
     32void finish( Server & mutex this ) {
     33        this.done++;
    3334}
    3435
    35 void finish( Server & mutex this ) { }
    36 
    3736void main( Server & this ) {
     37        MAIN_LOOP:
    3838        for() {
    3939                waitfor( ^?{} : this ) {
    4040                        break;
    4141                }
    42                 or when( this.cnt < NFUTURES ) waitfor( call: this ) {
    43                         if (this.cnt == NFUTURES) {
    44                                 process(this);
     42                or waitfor( call: this ) {
     43                        if (this.pending != NFUTURES) { continue MAIN_LOOP; }
     44
     45                        this.pending = 0;
     46                        fulfil( *this.request, this.iteration );
     47                        this.iteration++;
     48
     49                        for(NFUTURES) {
     50                                waitfor( finish: this );
    4551                        }
    46                 }
    47                 or waitfor( finish: this ) {
    48                         if (this.cnt == NFUTURES) {
    49                                 reset( *this.request );
    50                                 this.cnt = 0;
    51                         }
     52
     53                        reset( *this.request );
     54                        this.done = 0;
    5255                }
    5356        }
     
    5760Server * the_server;
    5861thread Worker {};
     62void ?{}(Worker & this) {
     63        ((thread&)this){"Worker Thread"};
     64}
     65
    5966multi_future(int) * shared_future;
    6067
Note: See TracChangeset for help on using the changeset viewer.