This is the mail archive of the cygwin-patches mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Cygwin: timerfd: avoid a deadlock


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]