Changes in / [c54ca97:39e6309]


Ignore:
Location:
tests/exceptions
Files:
2 edited

Legend:

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

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

    rc54ca97 r39e6309  
    11#include <fstream.hfa>
    22#include <thread.hfa>
     3#include <coroutine.hfa>
     4#include <stdlib.hfa>
    35#include <fstream.hfa>
    4 #include <mutex_stmt.hfa>
    56
    6 exception num_ping_pongs { int num; };
    7 vtable(num_ping_pongs) num_ping_pongs_vt;
     7exception num_pings { int num; };
     8vtable(num_pings) num_pings_vt;
    89
    9 thread Ping_Pong {
    10         char * name;
    11         int cnt;
    12         num_ping_pongs except;
    13         Ping_Pong & partner;
    14 };
     10exception num_pongs { int num; };
     11vtable(num_pongs) num_pongs_vt;
    1512
    16 void ?{}( Ping_Pong & this, char * name ) with( this ) {
    17         this.name = name;
    18         cnt = 0;
    19         ?{}( except, &num_ping_pongs_vt, 0 );
     13thread Ping;
     14thread Pong { Ping & p; int cnt; };
     15thread Ping { Pong & p; int cnt; };
     16
     17int numtimes = 100000;
     18
     19void 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    }
    2034}
    2135
    22 int numtimes = 100;
    23 
    24 void 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";
     36void 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    }
    4551}
    4652
    4753int main() {
    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";
     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";
    5865}
     66
Note: See TracChangeset for help on using the changeset viewer.