From 0c6b402b4add4ef20a6ba48d412b38faa0c8caba Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Tue, 10 Jan 2017 22:07:05 +0100 Subject: Check for EINT in semaphore wait. --- src/semaphore.cc | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/semaphore.cc b/src/semaphore.cc index a7c8e74..fdc33f1 100644 --- a/src/semaphore.cc +++ b/src/semaphore.cc @@ -168,6 +168,20 @@ void Semaphore::wait() #elif DG_PLATFORM == DG_PLATFORM_OSX MPWaitOnSemaphore(prv->semaphore, kDurationForever); #else - sem_wait(&prv->semaphore); +again: + int ret = sem_wait(&prv->semaphore); + if(ret < 0) + { + if(errno == EINTR) + { + // The wait were interrupted prematurely so we need to wait again + // To prevent an infinite loop-like behaviour we make a short sleep. + std::this_thread::sleep_for(std::chrono::milliseconds(1)); + goto again; + } + + perror("sem_wait()"); + assert(false); + } #endif } -- cgit v1.2.3