-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTryMe.cpp
More file actions
47 lines (41 loc) · 1.46 KB
/
TryMe.cpp
File metadata and controls
47 lines (41 loc) · 1.46 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
#include <iostream>
#include <GenSync/Syncs/GenSync.h>
int main() {
// BUILD the first host
GenSync host1 = GenSync::Builder().
setProtocol(GenSync::SyncProtocol::CPISync). // CPISync protocol
setComm(GenSync::SyncComm::socket). // communicate over network sockets
setMbar(5). // required parameter for CPISync
build();
// BUILD the second host
GenSync host2 = GenSync::Builder().
setProtocol(GenSync::SyncProtocol::CPISync).
setComm(GenSync::SyncComm::socket).
setMbar(5).
build();
// ADD elements to each host
// ... host 1
host1.addElem(make_shared<DataObject>('a')); // DataObject containing a character 'a'
host1.addElem(make_shared<DataObject>('b'));
host1.addElem(make_shared<DataObject>('c'));
// ... host 2
host2.addElem(make_shared<DataObject>('b'));
host2.addElem(make_shared<DataObject>('d'));
// FORK into two processes
if (fork()) {
// ... PARENT process
host1.clientSyncBegin(0); // set up the 0-th synchronizer and connect to a server
cout << "host 1 now has ";
for (auto &i: host1.dumpElements()) // print out the elements at host 1
cout << i << " ";
cout << endl;
}
else {
// ... CHILD process
host2.serverSyncBegin(0); // set up the 0-th synchronizer and wait for connections
cout << "host 2 now has ";
for (auto &i: host2.dumpElements()) // print out the elements at host 2
cout << i << " ";
cout << endl;
}
}