[PATCH] Cygwin: timerfd: avoid a deadlock

Ken Brown kbrown@cornell.edu
Mon Jun 24 20:19:00 GMT 2019


If a timer expires while the timerfd thread is in its inner loop,
check for the thread cancellation event before trying to enter
a_critical_section.  It's possible that timerfd_tracker::dtor has
entered its critical section and is trying to cancel the thread.  See
http://www.cygwin.org/ml/cygwin/2019-06/msg00096.html.
---
 winsup/cygwin/timerfd.cc | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/winsup/cygwin/timerfd.cc b/winsup/cygwin/timerfd.cc
index 8e4c94e66..e8261ef2e 100644
--- a/winsup/cygwin/timerfd.cc
+++ b/winsup/cygwin/timerfd.cc
@@ -137,6 +137,11 @@ timerfd_tracker::thread_func ()
 	      continue;
 	    }
 
+	  /* Avoid a deadlock if dtor has just entered its critical
+	     section and is trying to cancel the thread. */
+	  if (IsEventSignalled (cancel_evt))
+	    goto canceled;
+
 	  if (!enter_critical_section ())
 	    continue;
 	  /* Make sure we haven't been abandoned and/or disarmed
-- 
2.21.0



More information about the Cygwin-patches mailing list