Overflow cygthreads (those which use simplestub) don't set notify_detached event which may cause timer_delete to hung

Rafal Zwierz rzwierz@googlemail.com
Thu Aug 25 19:06:00 GMT 2011


I think that this is a problem in cygthreads, but since I have been
looking at cygwin for less than two weeks I might as well be quite

The problem can be reproduced with Cygwin 1.7.9-1 and also with
today's checkout of the code.

To repro run this program form the attachment (compiled using: g++ main.cc)

One should observe the program hanging when deleting timer. On my
computer it usually is timer 31, but depending on race conditions you
might get a different one. If you don't get the problem then try
increasing TIMERS.

After spending long hours looking at cygwinthread.cc code I have come
up with the following patch to fix the problem. I believe that the
solution should be bullet-proof also if someone terminates the thread
(thread_terminate()) or calls detach(), but since it was the first
time I looked at the cygwin code I might as well be wrong.

* cygthread.cc (cygthread::simplestub): Notify that the thread has
detached also in freerange thread case.

Any comments are most welcome,

Best wishes,
P.S. Please note that another (completely separate) problem with
freerange threads leaking memory in auto_release case exists. I will
create another post with info about that.
-------------- next part --------------
Index: src/winsup/cygwin/cygthread.cc
RCS file: /cvs/src/src/winsup/cygwin/cygthread.cc,v
retrieving revision 1.85
diff -u -p -r1.85 cygthread.cc
--- src/winsup/cygwin/cygthread.cc	30 Jul 2011 20:50:23 -0000	1.85
+++ src/winsup/cygwin/cygthread.cc	25 Aug 2011 18:44:32 -0000
@@ -136,7 +136,11 @@ cygthread::simplestub (VOID *arg)
   cygthread *info = (cygthread *) arg;
   _my_tls._ctinfo = info;
   info->stack_ptr = &arg;
+  HANDLE notify = info->notify_detached;
   info->callfunc (true);
+  if (notify) 
+     SetEvent(notify);
   return 0;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: main.cc
Type: application/octet-stream
Size: 1176 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin-patches/attachments/20110825/3ad35ccc/attachment.obj>

More information about the Cygwin-patches mailing list