- Timestamp:
- Sep 2, 2022, 12:23:54 PM (2 years ago)
- Branches:
- ADT, ast-experimental, master, pthread-emulation
- Children:
- 2284d20
- Parents:
- e228f46
- Location:
- tests/io
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
tests/io/comp_basic.cfa
re228f46 r680137a 27 27 28 28 struct { 29 30 29 barrier & bar; 30 int pipe[2]; 31 31 32 32 } globals; … … 45 45 thread Reader {}; 46 46 void main(Reader & this) { 47 47 bool do_read = has_user_level_blocking( (fptr_t)async_read ); 48 48 49 50 51 52 53 54 55 56 49 for(TIMES) { 50 io_future_t f; 51 if ( do_read ) { 52 char thrash[1]; 53 async_read(f, globals.pipe[0], thrash, 1, 0); 54 } else { 55 fulfil(f, 0); // If we don't have user-level blocking just play along 56 } 57 57 58 58 block( globals.bar ); 59 59 60 60 yield( prng( this, 15 ) ); 61 61 62 62 unsigned i = __atomic_add_fetch( &counter, 1, __ATOMIC_SEQ_CST ); 63 63 if(0 == (i % 100)) sout | i; 64 64 65 65 wait( f ); 66 66 67 68 67 if(f.result < 0) 68 abort | "Read error" | -f.result | ":" | strerror(-f.result); 69 69 70 71 70 block( globals.bar ); 71 } 72 72 } 73 73 … … 77 77 thread Writer {}; 78 78 void main(Writer & this) { 79 80 79 for(TIMES) { 80 block( globals.bar ); 81 81 82 82 sleep( 1`us ); 83 83 84 85 86 87 84 char buf[1] = { '+' }; 85 int ret = write( globals.pipe[1], buf, 1 ); 86 if(ret < 0) 87 abort | "Write error" | errno | ":" | strerror(errno); 88 88 89 90 89 block( globals.bar ); 90 } 91 91 } 92 92 93 93 int main() { 94 95 96 97 98 94 barrier bar = { 2 }; 95 &globals.bar = &bar; 96 int ret = pipe(globals.pipe); 97 if(ret != 0) 98 abort | "Pipe error" | errno | ":" | strerror(errno); 99 99 100 100 sout | "starting"; 101 101 { 102 102 Reader ior; 103 103 Writer iow; 104 104 } 105 105 sout | "done"; -
tests/io/comp_fair.cfa
re228f46 r680137a 27 27 28 28 struct { 29 30 29 barrier & bar; 30 int pipe[2]; 31 31 32 32 } globals; … … 65 65 thread Reader {}; 66 66 void main(Reader & this) { 67 67 bool do_read = has_user_level_blocking( (fptr_t)async_read ); 68 68 69 70 71 72 73 74 75 76 69 for(TIMES) { 70 io_future_t f; 71 if ( do_read ) { 72 char thrash[1]; 73 async_read(f, globals.pipe[0], thrash, 1, 0); 74 } else { 75 fulfil(f, 0); // If we don't have user-level blocking just play along 76 } 77 77 78 78 block( globals.bar ); 79 79 80 80 yield( prng( this, 15 ) ); 81 81 82 82 unsigned i = __atomic_add_fetch( &counter, 1, __ATOMIC_SEQ_CST ); 83 83 if(0 == (i % 100)) sout | i; 84 84 85 85 wait( f ); 86 86 87 88 87 if(f.result < 0) 88 abort | "Read error" | -f.result | ":" | strerror(-f.result); 89 89 90 91 90 block( globals.bar ); 91 } 92 92 } 93 93 … … 97 97 thread Writer {}; 98 98 void main(Writer & this) { 99 100 99 for(TIMES) { 100 block( globals.bar ); 101 101 102 102 sleep( 1`us ); 103 103 104 105 106 107 104 char buf[1] = { '+' }; 105 int ret = write( globals.pipe[1], buf, 1 ); 106 if(ret < 0) 107 abort | "Write error" | errno | ":" | strerror(errno); 108 108 109 110 109 block( globals.bar ); 110 } 111 111 } 112 112 … … 122 122 123 123 int main() { 124 125 126 127 128 124 barrier bar = { 2 }; 125 &globals.bar = &bar; 126 int ret = pipe(globals.pipe); 127 if(ret != 0) 128 abort | "Pipe error" | errno | ":" | strerror(errno); 129 129 130 130 processor p; … … 134 134 Spinner s; 135 135 Reader ior; 136 136 Writer iow; 137 137 } 138 138 sout | "done";
Note: See TracChangeset
for help on using the changeset viewer.