Ticket #6549: test2_win.cpp.txt

File test2_win.cpp.txt, 1.3 KB (added by Josh Davidson <josh.davidson@…>, 11 years ago)

Native Windows (2of 2)

Line 
1#include <boost/date_time/posix_time/posix_time.hpp>
2using namespace boost::posix_time;
3#include <iostream>
4using namespace std;
5
6#include <Windows.h>
7
8int main() {
9
10 const size_t iterations = 100000;
11
12 HANDLE sem1 = OpenSemaphore(SEMAPHORE_ALL_ACCESS , false, "wsem1");
13 HANDLE sem2 = OpenSemaphore(SEMAPHORE_ALL_ACCESS , false, "wsem2");
14
15 if(sem1 == NULL || sem2 == NULL) {
16 cerr << "HOUSTON WE HAVE A PROBLEM" << endl;
17 }
18
19 DWORD waitResult;
20 LONG previous;
21 ptime start = boost::posix_time::microsec_clock::local_time();
22 for(size_t i = 0; i < iterations; ++i) {
23 if(!ReleaseSemaphore(sem1, 1, &previous)) {
24 cerr << "Release semaphore A error: " << GetLastError() << endl;
25 }
26// else {
27// cerr << "Previous A: " << previous << endl;
28// }
29
30 waitResult = WaitForSingleObject(sem2, INFINITE);
31 if(waitResult != WAIT_OBJECT_0) {
32 cerr << "WTF A " << waitResult << " / " << GetLastError() << endl;
33 break;
34 }
35// else {
36// cerr << "GOT A" << endl;
37// }
38
39 }
40
41 ptime end = boost::posix_time::microsec_clock::local_time();
42 time_duration delta = end - start;
43
44 double seconds = double(delta.total_nanoseconds())/1000000000.0;
45
46 cout << "Total elapsed time: " << seconds << endl;;
47 cout << "Time per iteration: " << (seconds/double(iterations)) << endl;
48 return 0;
49}