diff --git a/projects/rocr-runtime/runtime/hsa-runtime/core/util/lnx/os_linux.cpp b/projects/rocr-runtime/runtime/hsa-runtime/core/util/lnx/os_linux.cpp index 84021f15b0..0cc65b1ce6 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/core/util/lnx/os_linux.cpp +++ b/projects/rocr-runtime/runtime/hsa-runtime/core/util/lnx/os_linux.cpp @@ -369,6 +369,14 @@ bool WaitSemaphore(Semaphore sem) { } void PostSemaphore(Semaphore sem) { + int waitval = 1; + if (sem_getvalue(*(sem_t**)&sem, &waitval)) + assert(false && "Failed to get semaphore waiters"); + + /* sem_getvalue return <= 0 when there are threads blocked on sem_wait */ + if (waitval > 0) + return; + if (sem_post(*(sem_t**)&sem)) assert(false && "Failed to post semaphore"); }