Changeset ec22220


Ignore:
Timestamp:
Dec 10, 2024, 3:07:59 PM (8 days ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
64f3b9f
Parents:
6e6e372
Message:

formatting

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/concurrency/waituntil/channel_close.cfa

    r6e6e372 rec22220  
    1 #include <select.hfa>
     1#include <fstream.hfa>
    22#include <thread.hfa>
    33#include <channel.hfa>
    44#include <time.hfa>
    55
    6 channel(long long int) A, B;
     6channel(ssize_t) A, B;
    77
    8 volatile long long int inserts = 0;
    9 volatile long long int removes = 0;
     8volatile size_t inserts = 0, removes = 0;
    109
    1110thread Producer {};
    1211void main( Producer & this ) {
    1312    try {
    14         for( long long int i = 0;;i++ ) {
     13        for( size_t i; 0~@ ) {
    1514            waituntil( A << i ) { inserts++; }
    1615            and waituntil( B << i ) { inserts++; }
     
    2221thread Consumer {}; // ensures that the changing when states of Server1 don't result in a deadlock
    2322void main( Consumer & this ) {
    24     long long int in, in2, A_removes = 0, B_removes = 0;
     23    ssize_t in, in2, A_removes = 0, B_removes = 0;
     24
    2525    try {
    26         for( ;; ) {
     26        for () {
    2727            if ( useAnd ) {
    2828                waituntil( (in << A) ) { __atomic_thread_fence( __ATOMIC_SEQ_CST ); assert( A_removes == in ); A_removes++; removes++; }
     
    3333            or waituntil( (in << B) ) { __atomic_thread_fence( __ATOMIC_SEQ_CST ); ( B_removes == in ); B_removes++; removes++; }
    3434        }
    35     } catchResume ( channel_closed * e ) {} // continue to remove until would block
    36     catch ( channel_closed * e ) {}
     35    } catchResume ( channel_closed * e ) {                              // continue to remove until would block
     36        } catch ( channel_closed * e ) {}
     37
    3738    try {
    38         for( ;; )
     39        for ()
    3940            waituntil( (in << A) ) { __atomic_thread_fence( __ATOMIC_SEQ_CST ); assert( A_removes == in ); A_removes++; removes++; }
    40     } catchResume ( channel_closed * e ) {} // continue to remove until would block
    41     catch ( channel_closed * e ) {}
     41    } catchResume ( channel_closed * e ) {                              // continue to remove until would block
     42        } catch ( channel_closed * e ) {}
     43
    4244    try {
    43         for( ;; )
     45        for ()
    4446            waituntil( (in << B) ) { __atomic_thread_fence( __ATOMIC_SEQ_CST ); assert( B_removes == in ); B_removes++; removes++; }
    45     } catchResume ( channel_closed * e ) {} // continue to remove until would block
    46     catch ( channel_closed * e ) {}
     47    } catchResume ( channel_closed * e ) {                              // continue to remove until would block
     48        } catch ( channel_closed * e ) {}
    4749}
    4850
     51int main( int argc, char * argv[] ) {
     52        size_t time = 5;
    4953
    50 size_t time = 5;
    51 int main( int argc, char * argv[] ) {
    5254    if ( argc == 2 )
    5355        time = atoi( argv[1] );
     
    5759    B{5};
    5860
    59     printf("start OR\n");
     61    sout | "start OR";
    6062    {
    6163        Producer p;
    6264        Consumer c;
    6365        sleep(time`s);
    64         printf("done sleep\n");
    65         printf("closing A\n");
    66         close(A);
    67         printf("closing B\n");
    68         close(B);
     66        sout | "done sleep";
     67        sout | "closing A";
     68        close( A );
     69        sout | "closing B";
     70        close( B );
    6971    }
    7072    if ( inserts != removes )
    71         printf("CHECKSUM MISMATCH!! Producer got: %lld, Consumer got: %lld\n", inserts, removes);
    72     printf("done\n");
     73        sout | "CHECKSUM MISMATCH!! Producer got:" | inserts | ", Consumer got:" | removes;
     74    sout | "done";
    7375    ^A{};
    7476    ^B{};
    7577
    7678    useAnd = true;
    77 
    78     inserts = 0;
    79     removes = 0;
     79    inserts = removes = 0;
    8080    A{5};
    8181    B{5};
    82     printf("start AND\n");
     82    sout | "start AND";
    8383    {
    8484        Producer p;
    8585        Consumer c;
    86         sleep(time`s);
    87         printf("done sleep\n");
    88         printf("closing A\n");
    89         close(A);
    90         printf("closing B\n");
    91         close(B);
     86        sleep( time`s );
     87        sout | "done sleep";
     88        sout | "closing A";
     89        close( A );
     90        sout | "closing B";
     91        close( B );
    9292    }
    9393    if ( inserts != removes )
    94         printf("CHECKSUM MISMATCH!! Producer got: %lld, Consumer got: %lld\n", inserts, removes);
    95     printf("done\n");
     94        sout | "CHECKSUM MISMATCH!! Producer got:" | inserts | ", Consumer got:" | removes;
     95    sout | "done";
    9696}
Note: See TracChangeset for help on using the changeset viewer.