Changeset a2eb21a for tests


Ignore:
Timestamp:
Jul 11, 2023, 9:59:11 AM (11 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
c54ca97
Parents:
f80e0f1e
Message:

fix problems in pingpong_nonlocal

Location:
tests/exceptions
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • tests/exceptions/.expect/pingpong_nonlocal.txt

    rf80e0f1e ra2eb21a  
    1 start
    2 done
     1main start
     2ping start
     3pong start
     4pong catchResume 0 0
     5ping catchResume 0 1
     6pong catchResume 0 2
     7ping catchResume 1 3
     8pong catchResume 2 4
     9ping catchResume 3 5
     10pong catchResume 4 6
     11ping catchResume 5 7
     12pong catchResume 6 8
     13ping catchResume 7 9
     14pong catchResume 8 10
     15ping catchResume 9 11
     16pong catchResume 10 12
     17ping catchResume 11 13
     18pong catchResume 12 14
     19ping catchResume 13 15
     20pong catchResume 14 16
     21ping catchResume 15 17
     22pong catchResume 16 18
     23ping catchResume 17 19
     24pong catchResume 18 20
     25ping catchResume 19 21
     26pong catchResume 20 22
     27ping catchResume 21 23
     28pong catchResume 22 24
     29ping catchResume 23 25
     30pong catchResume 24 26
     31ping catchResume 25 27
     32pong catchResume 26 28
     33ping catchResume 27 29
     34pong catchResume 28 30
     35ping catchResume 29 31
     36pong catchResume 30 32
     37ping catchResume 31 33
     38pong catchResume 32 34
     39ping catchResume 33 35
     40pong catchResume 34 36
     41ping catchResume 35 37
     42pong catchResume 36 38
     43ping catchResume 37 39
     44pong catchResume 38 40
     45ping catchResume 39 41
     46pong catchResume 40 42
     47ping catchResume 41 43
     48pong catchResume 42 44
     49ping catchResume 43 45
     50pong catchResume 44 46
     51ping catchResume 45 47
     52pong catchResume 46 48
     53ping catchResume 47 49
     54pong catchResume 48 50
     55ping catchResume 49 51
     56pong catchResume 50 52
     57ping catchResume 51 53
     58pong catchResume 52 54
     59ping catchResume 53 55
     60pong catchResume 54 56
     61ping catchResume 55 57
     62pong catchResume 56 58
     63ping catchResume 57 59
     64pong catchResume 58 60
     65ping catchResume 59 61
     66pong catchResume 60 62
     67ping catchResume 61 63
     68pong catchResume 62 64
     69ping catchResume 63 65
     70pong catchResume 64 66
     71ping catchResume 65 67
     72pong catchResume 66 68
     73ping catchResume 67 69
     74pong catchResume 68 70
     75ping catchResume 69 71
     76pong catchResume 70 72
     77ping catchResume 71 73
     78pong catchResume 72 74
     79ping catchResume 73 75
     80pong catchResume 74 76
     81ping catchResume 75 77
     82pong catchResume 76 78
     83ping catchResume 77 79
     84pong catchResume 78 80
     85ping catchResume 79 81
     86pong catchResume 80 82
     87ping catchResume 81 83
     88pong catchResume 82 84
     89ping catchResume 83 85
     90pong catchResume 84 86
     91ping catchResume 85 87
     92pong catchResume 86 88
     93ping catchResume 87 89
     94pong catchResume 88 90
     95ping catchResume 89 91
     96pong catchResume 90 92
     97ping catchResume 91 93
     98pong catchResume 92 94
     99ping catchResume 93 95
     100pong catchResume 94 96
     101ping catchResume 95 97
     102pong catchResume 96 98
     103ping catchResume 97 99
     104pong catch 98 100
     105pong end
     106ping catch 99 101
     107ping end
     108main end
  • tests/exceptions/pingpong_nonlocal.cfa

    rf80e0f1e ra2eb21a  
    11#include <fstream.hfa>
    22#include <thread.hfa>
    3 #include <coroutine.hfa>
    4 #include <stdlib.hfa>
    53#include <fstream.hfa>
     4#include <mutex_stmt.hfa>
    65
    7 exception num_pings { int num; };
    8 vtable(num_pings) num_pings_vt;
     6exception num_ping_pongs { int num; };
     7vtable(num_ping_pongs) num_ping_pongs_vt;
    98
    10 exception num_pongs { int num; };
    11 vtable(num_pongs) num_pongs_vt;
     9thread Ping_Pong {
     10        char * name;
     11        int cnt;
     12        num_ping_pongs except;
     13        Ping_Pong & partner;
     14};
    1215
    13 thread Ping;
    14 thread Pong { Ping & p; int cnt; };
    15 thread Ping { Pong & p; int cnt; };
    16 
    17 int numtimes = 100000;
    18 
    19 void main( Pong & this ) with(this) {
    20     try {
    21         for ( ;; ) {
    22             while( !poll( this ) ) {}
    23             num_pongs except{ &num_pongs_vt, cnt + 1 };
    24             resumeAt( p, except );
    25         }
    26     } catchResume ( num_pings * e; e->num < numtimes ) {
    27         cnt = e->num;
    28     } catch( num_pings * e ) {
    29         if ( e->num == numtimes ){
    30             num_pongs except{ &num_pongs_vt, e->num + 1 };
    31             resumeAt( p, except );
    32         }
    33     }
     16void ?{}( Ping_Pong & this, char * name ) with( this ) {
     17        this.name = name;
     18        cnt = 0;
     19        ?{}( except, &num_ping_pongs_vt, 0 );
    3420}
    3521
    36 void main( Ping & this ) with(this) {
    37     try {
    38         for ( ;; ) {
    39             while( !poll( this ) ) {}
    40             num_pings except{ &num_pings_vt, cnt + 1 };
    41             resumeAt( p, except );
    42         }
    43     } catchResume ( num_pongs * e; e->num < numtimes ) {
    44         cnt = e->num;
    45     } catch( num_pongs * e ) {
    46         if ( e->num == numtimes ){
    47             num_pings except{ &num_pings_vt, e->num + 1 };
    48             resumeAt( p, except );
    49         }
    50     }
     22int numtimes = 100;
     23
     24void main( Ping_Pong & this ) with( this ) {
     25        void inc_resume_at( int value ) {
     26                except.num = value + 1;
     27                resumeAt( partner, except );
     28        }
     29        mutex( sout ) sout | name | "start";
     30        try {
     31                for () {
     32                        while( ! poll( this ) ) { yield(); }
     33            inc_resume_at( cnt );
     34                }
     35        } catchResume( num_ping_pongs * e; e->num < numtimes ) {
     36                mutex( sout ) sout | name | "catchResume" | cnt | e->num;
     37                cnt = e->num;
     38        } catch( num_ping_pongs * e ) {
     39                mutex( sout ) sout | name | "catch" | cnt | e->num;
     40                if ( e->num == numtimes ) {
     41            inc_resume_at( e->num );
     42                }
     43        }
     44        mutex( sout ) sout | name | "end";
    5145}
    5246
    5347int main() {
    54     processor p;
    55     sout | "start";
    56     {
    57         Ping ping;
    58         Pong pong;
    59         &ping.p = &pong;
    60         &pong.p = &ping;
    61         num_pings except{ &num_pings_vt, 0 };
    62         resumeAt( pong, except );
    63     }
    64     sout | "done";
     48        processor p;
     49        sout | "main start";
     50        {
     51                Ping_Pong ping { "ping" }, pong{ "pong" };
     52                &ping.partner = &pong;                                                  // create cycle
     53                &pong.partner = &ping;
     54                num_ping_pongs except{ &num_ping_pongs_vt, 0 };
     55                resumeAt( pong, except );
     56        }
     57        sout | "main end";
    6558}
    66 
Note: See TracChangeset for help on using the changeset viewer.