Last change
on this file since 7a29392f was
8b84973,
checked in by caparsons <caparson@…>, 13 months ago
|
updated waituntil benchmarks to use new channel arrow syntax
|
-
Property mode set to
100644
|
File size:
1.6 KB
|
Rev | Line | |
---|
[14e1053] | 1 | #include <select.hfa> |
---|
| 2 | #include <thread.hfa> |
---|
| 3 | #include <channel.hfa> |
---|
| 4 | #include <locks.hfa> |
---|
| 5 | #include <fstream.hfa> |
---|
| 6 | #include <stdio.h> |
---|
| 7 | #include <time.hfa> |
---|
| 8 | #include <string.h> |
---|
| 9 | |
---|
| 10 | size_t ChannelSize = 100, Channels = 2; |
---|
| 11 | |
---|
| 12 | channel(size_t) * chans; |
---|
| 13 | |
---|
| 14 | size_t globalTotal = 0; |
---|
| 15 | int cons_counter = 0, prod_counter = 0; |
---|
| 16 | |
---|
| 17 | thread SelectConsumer {}; |
---|
| 18 | void main( SelectConsumer & this ) { |
---|
| 19 | size_t val, i = 0; |
---|
| 20 | try { |
---|
| 21 | for(;; i++ ) { |
---|
| 22 | waituntil( val << chans[0] ) {} or waituntil( val << chans[1] ) {} |
---|
| 23 | } |
---|
| 24 | } catch( channel_closed * e ) {} |
---|
| 25 | __atomic_fetch_add( &globalTotal, i, __ATOMIC_SEQ_CST ); |
---|
| 26 | } |
---|
| 27 | |
---|
| 28 | thread SelectProducer {}; |
---|
| 29 | void main( SelectProducer & this ) { |
---|
| 30 | try { |
---|
| 31 | for( size_t i = 0;; i++ ) { |
---|
[8b84973] | 32 | waituntil( chans[0] << i ) {} or waituntil( chans[1] << i ) {} |
---|
[14e1053] | 33 | } |
---|
| 34 | } catch( channel_closed * e ) {} |
---|
| 35 | } |
---|
| 36 | |
---|
| 37 | thread Consumer {}; |
---|
| 38 | void main( Consumer & this ) { |
---|
| 39 | size_t val, i = 0; |
---|
| 40 | try { |
---|
| 41 | for(;; i++ ) { |
---|
| 42 | remove( chans[1] ); |
---|
| 43 | } |
---|
| 44 | } catch( channel_closed * e ) {} |
---|
| 45 | __atomic_fetch_add( &globalTotal, i, __ATOMIC_SEQ_CST ); |
---|
| 46 | } |
---|
| 47 | |
---|
| 48 | thread Producer {}; |
---|
| 49 | void main( Producer & this ) { |
---|
| 50 | try { |
---|
| 51 | for( size_t i = 0;; i++ ) { |
---|
| 52 | insert( chans[1], i ); |
---|
| 53 | } |
---|
| 54 | } catch( channel_closed * e ) {} |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | int main( int argc, char * argv[] ) { |
---|
| 58 | processor p[3]; |
---|
| 59 | |
---|
| 60 | chans = aalloc( Channels ); |
---|
| 61 | for ( i; Channels ) |
---|
| 62 | chans[i]{ ChannelSize }; |
---|
| 63 | |
---|
| 64 | { |
---|
| 65 | Producer p; |
---|
| 66 | SelectProducer sp; |
---|
| 67 | Consumer c; |
---|
| 68 | SelectConsumer sc; |
---|
| 69 | |
---|
| 70 | sleep(10`s); |
---|
| 71 | |
---|
| 72 | for ( i; Channels ) |
---|
| 73 | close( chans[i] ); |
---|
| 74 | } |
---|
| 75 | adelete( chans ); |
---|
| 76 | printf("%zu\n", globalTotal); |
---|
| 77 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.