#include #include #include #include #include #include #include size_t total_operations = 0; size_t Processors = 1, Tasks = 1; owner_lock o; // typedef channel_base( int, exp_backoff_then_block_lock ) Channel; typedef channel( int ) Channel; Channel * chain; bool done = false; thread Task {}; void main(Task & this) { size_t runs = 0; for ( ;; ) { if ( done ) break; remove( *chain ); insert( *chain, 0 ); runs++; } lock( o ); total_operations += runs; unlock( o ); } int main( int argc, char * argv[] ) { switch ( argc ) { case 3: if ( strcmp( argv[2], "d" ) != 0 ) { // default ? Tasks = atoi( argv[2] ); if ( Tasks < 1 ) goto Usage; } // if case 2: if ( strcmp( argv[1], "d" ) != 0 ) { // default ? Processors = atoi( argv[1] ); if ( Processors < 1 ) goto Usage; } // if case 1: // use defaults break; default: Usage: sout | "Usage: " | argv[0] | " [ processors (> 0) | 'd' (default " | Processors | ") ] [ channel size (>= 0) | 'd' (default " | Tasks | ") ]" ; exit( EXIT_FAILURE ); } // switch Tasks = Processors; processor proc[Processors - 1]; Channel chainChan{ 2 * Tasks }; insert( chainChan, 0 ); chain = &chainChan; { Task t[Tasks]; sleep(10`s); done = true; for ( j; Tasks ) insert( chainChan, 0 ); } sout | total_operations; return 0; }