$NetBSD: patch-aa,v 1.2 2015/08/25 13:41:24 leot1990 Exp $

--- event.cpp.orig	2014-03-04 16:47:15.000000000 +0000
+++ event.cpp
@@ -42,6 +42,12 @@
 //>
 //<decls and function prototypes
 
+#ifndef timespeccmp
+#define        timespeccmp(tvp, uvp, cmp)                                      \
+	(((tvp)->tv_sec == (uvp)->tv_sec) ?			       \
+	   ((tvp)->tv_nsec cmp (uvp)->tv_nsec) :		       \
+	   ((tvp)->tv_sec cmp (uvp)->tv_sec))
+#endif
 
 // my_mutex: protects my_thread_is_talking,
 static pthread_mutex_t my_mutex;
@@ -410,10 +416,15 @@ ENTER("sleep_until_timeout_or_stop_reque
        to.tv_sec, to.tv_nsec,
        ts.tv_sec, ts.tv_nsec);
 
-	while ((err = sem_timedwait(&my_sem_stop_is_required, &ts)) == -1
-		&& errno == EINTR)
+	while ((err = sem_trywait(&my_sem_stop_is_required)) == -1 
+		&& (errno == EINTR || errno == EAGAIN))
 	{
 		continue; // Restart when interrupted by handler
+		struct timespec help;
+		clock_gettime2(&help);
+		if (timespeccmp(&help, &ts, >=))
+			break;
+		sched_yield();
 	}
 
 	assert (gettimeofday(&tv, NULL) != -1);
