source: doc/theses/colby_parsons_MMAth/benchmarks/channels/cfa/ping_pong.cfa@ bb7422a

ADT ast-experimental
Last change on this file since bb7422a was 76a8400, checked in by caparson <caparson@…>, 2 years ago

added all cfa benchmarks, contend is the only one used in the thesis, but other may be used later so Im keeping them around

  • Property mode set to 100644
File size: 1.0 KB
Line 
1#include <locks.hfa>
2#include <fstream.hfa>
3#include <stdio.h>
4#include <channel.hfa>
5#include <thread.hfa>
6#include <time.hfa>
7#include <string.h>
8
9size_t total_operations = 0;
10
11// typedef channel_base( int, exp_backoff_then_block_lock ) Channel;
12typedef channel( int ) Channel;
13
14Channel * ping;
15Channel * pong;
16
17bool done = false;
18
19thread Pong {};
20void main(Pong & this) {
21 for ( ;; ) {
22 if ( done ) break;
23 insert( *ping, 0 );
24 remove( *pong );
25 }
26}
27
28thread Ping {};
29void main(Ping & this) {
30 size_t runs = 0;
31 for ( ;; ) {
32 if ( done ) break;
33 remove( *ping );
34 insert( *pong, 1 );
35 total_operations++;
36 }
37}
38
39
40int main( int argc, char * argv[] ) {
41 processor proc[1];
42
43 Channel pingChan{ 2 };
44 Channel pongChan{ 2 };
45
46 ping = &pingChan;
47 pong = &pongChan;
48
49 {
50 Ping pi;
51 Pong po;
52 sleep(10`s);
53 done = true;
54 insert( *pong, 2 );
55 insert( *ping, 2 );
56 }
57
58 sout | total_operations;
59
60 // sout | "done";
61 return 0;
62}
Note: See TracBrowser for help on using the repository browser.