| 1 | #include <boost/interprocess/sync/named_semaphore.hpp>
|
|---|
| 2 | using namespace boost::interprocess;
|
|---|
| 3 |
|
|---|
| 4 | #include <boost/date_time/posix_time/posix_time.hpp>
|
|---|
| 5 | using namespace boost::posix_time;
|
|---|
| 6 | #include <iostream>
|
|---|
| 7 | using namespace std;
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 | int main() {
|
|---|
| 11 |
|
|---|
| 12 | const size_t iterations = 100000;
|
|---|
| 13 | named_semaphore sem1(open_only_t(), "sem1");
|
|---|
| 14 | named_semaphore sem2(open_only_t(), "sem2");
|
|---|
| 15 |
|
|---|
| 16 | ptime start = boost::posix_time::microsec_clock::local_time();
|
|---|
| 17 | for(size_t i = 0; i < iterations; ++i) {
|
|---|
| 18 | sem1.post();
|
|---|
| 19 | sem2.wait();
|
|---|
| 20 | }
|
|---|
| 21 |
|
|---|
| 22 | ptime end = boost::posix_time::microsec_clock::local_time();
|
|---|
| 23 | time_duration delta = end - start;
|
|---|
| 24 |
|
|---|
| 25 | double seconds = double(delta.total_nanoseconds())/1000000000.0;
|
|---|
| 26 |
|
|---|
| 27 | cout << "Total elapsed time: " << seconds << endl;;
|
|---|
| 28 | cout << "Time per iteration: " << (seconds/double(iterations)) << endl;
|
|---|
| 29 | return 0;
|
|---|
| 30 | }
|
|---|