#include using namespace boost::posix_time; #include using namespace std; #include int main() { const size_t iterations = 100000; HANDLE sem1 = OpenSemaphore(SEMAPHORE_ALL_ACCESS , false, "wsem1"); HANDLE sem2 = OpenSemaphore(SEMAPHORE_ALL_ACCESS , false, "wsem2"); if(sem1 == NULL || sem2 == NULL) { cerr << "HOUSTON WE HAVE A PROBLEM" << endl; } DWORD waitResult; LONG previous; ptime start = boost::posix_time::microsec_clock::local_time(); for(size_t i = 0; i < iterations; ++i) { if(!ReleaseSemaphore(sem1, 1, &previous)) { cerr << "Release semaphore A error: " << GetLastError() << endl; } // else { // cerr << "Previous A: " << previous << endl; // } waitResult = WaitForSingleObject(sem2, INFINITE); if(waitResult != WAIT_OBJECT_0) { cerr << "WTF A " << waitResult << " / " << GetLastError() << endl; break; } // else { // cerr << "GOT A" << endl; // } } ptime end = boost::posix_time::microsec_clock::local_time(); time_duration delta = end - start; double seconds = double(delta.total_nanoseconds())/1000000000.0; cout << "Total elapsed time: " << seconds << endl;; cout << "Time per iteration: " << (seconds/double(iterations)) << endl; return 0; }