Advertisement
Bkmz

Untitled

Jan 11th, 2012
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.52 KB | None | 0 0
  1. // Semaphore_test.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include <stdio.h>
  5. #include <Windows.h>
  6. #include <fcntl.h>
  7.  
  8. HANDLE semaphore;
  9.  
  10. DWORD Limit = 5;
  11. DWORD timeout = 0;
  12.  
  13. DWORD res = 0;
  14.  
  15.  
  16. int main()
  17. {
  18.  
  19.     semaphore = OpenSemaphore(SEMAPHORE_ALL_ACCESS, false, (LPCWSTR)"sem");
  20.  
  21.     if (semaphore == NULL){
  22.         semaphore = CreateSemaphore(NULL, 3, Limit, (LPCWSTR)"sem");
  23.     }
  24.  
  25.     res = WaitForSingleObject(semaphore, timeout);
  26.    
  27.     printf("res: %i", &res);
  28.  
  29.  
  30.     system("PAUSE");
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement