May be this is stupid question for you .. but it doesn’t work for me! (New to WinRT .. may be windows too!) Just trying to create semaphore and trying to acquire that’s it .. nothing fancy. But it fails with WAIT_FAILED: 5 (Access denied)
void MainPage::simple_Sema_test1()
{
HANDLE p_sema;
DWORD ret, err;
p_sema = CreateSemaphoreEx(NULL, 1, MAX_LIMIT, L"sema1", 0, SEMAPHORE_MODIFY_STATE);
if(p_sema == NULL)
print_on_textbox("CreateSemaphoreEx Failed!\n");
ret = WaitForSingleObjectEx(p_sema, 1000, TRUE);
switch(ret){
case WAIT_ABANDONED:
print_on_textbox("WAIT_ABANDONED\n");
case WAIT_IO_COMPLETION:
print_on_textbox("WAIT_IO_COMPLETION\n");
case WAIT_OBJECT_0:
print_on_textbox("WAIT_OBJECT_0\n");
case WAIT_TIMEOUT:
print_on_textbox("WAIT_TIMEOUT\n");
case WAIT_FAILED:
print_on_textbox("WAIT_FAILED: " + (GetLastError()).ToString());
}
Edit <<< (Partially solved)
Create Semaphore with SEMAPHORE_ALL_ACCESS
i.e.
*sema = CreateSemaphoreEx(NULL, initial, MAX_LIMIT, L"sema1", 0, SEMAPHORE_ALL_ACCESS);
If anyone knows why it didn’t work with modify access then please explain!
To wait on a synchronization object, you must have
SYNCHRONIZEaccess rights:The
SEMAPHORE_ALL_ACCESSvalue includes theSYNCHRONIZEflag.