-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuC++SenderDynamic.cc
More file actions
49 lines (42 loc) · 1.37 KB
/
uC++SenderDynamic.cc
File metadata and controls
49 lines (42 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <iostream>
using namespace std;
#include <chrono>
using namespace chrono;
#include <uActor.h>
int Times = 100'000'000; // default values
time_point<steady_clock> starttime;
struct SMsg : public uActor::SenderMsg { int cnt; SMsg( int cnt ) : SenderMsg( uActor::Delete ), cnt( cnt ) {} };
_Actor Sender {
Allocation receive( Message & msg ) {
Case ( SMsg, msg ) {
if ( msg_d->cnt >= Times ) {
cout << Times << ' ' << (steady_clock::now() - starttime).count() / Times << "ns" << endl;
return Delete;
} // if
//cout << msg_d->cnt << endl;
*this | *new SMsg{ msg_d->cnt + 1 }; // message send self
} // Case
return Nodelete;
} // Send:::receive
}; // Sender
int main( int argc, char * argv[] ) {
switch ( argc ) {
case 2:
if ( strcmp( argv[1], "d" ) != 0 ) { Times = stoi( argv[1] ); }
if ( Times < 1 ) goto Usage;
case 1: // use defaults
break;
default:
Usage:
cerr << "Usage: " << argv[0] << " [ times (> 0) ]" << endl;
exit( EXIT_FAILURE );
} // switch
uActor::start(); // start actor system
starttime = steady_clock::now();
*(new Sender) | *new SMsg{ 0 };
uActor::stop(); // wait for all actors to terminate
} // main
// /usr/bin/time -f "%Uu %Ss %Er %Mkb" a.out
// Local Variables: //
// compile-command: "u++-work -g -Wall -Wextra -O3 -nodebug -DNDEBUG -multi uC++SenderDynamic.cc" //
// End: //