Ticket #6549: test1_win.cpp.txt

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

Native Windows (1 of 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 HANDLE sem1 = CreateSemaphore(NULL, 0, 1, "wsem1");
11
12 if(GetLastError() == ERROR_ALREADY_EXISTS) {
13 CloseHandle(sem1);
14 sem1 = CreateSemaphore(NULL, 0, 1, "wsem1");
15 }
16
17 HANDLE sem2 = CreateSemaphore(NULL, 0, 1, "wsem2");
18 if(GetLastError() == ERROR_ALREADY_EXISTS) {
19 CloseHandle(sem2);
20 sem1 = CreateSemaphore(NULL, 0, 1, "wsem2");
21 }
22
23 if(sem1 == NULL || sem2 == NULL) {
24 cerr << "HOUSTON WE HAVE A PROBLEM" << endl;
25 }
26
27 DWORD waitResult;
28 LONG previous;
29 while(true) {
30 waitResult = WaitForSingleObject(sem1, INFINITE);
31 if(waitResult != WAIT_OBJECT_0) {
32 cerr << "WTF B " << waitResult << " / " << GetLastError() << endl;
33 break;
34 }
35// else {
36// cerr << "Got B" << endl;
37// }
38
39 if(!ReleaseSemaphore(sem2, 1, &previous)) {
40 cerr << "Release semaphore B error: " << GetLastError() << endl;
41 }
42// else {
43// cerr << "Previous B: " << previous << endl;
44// }
45 }
46
47 return 0;
48}
49
50
51