Mail Archives: cygwin/2009/06/02/06:11:41
--------------030804020300020409010901
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Thomas Stalder wrote:
> Sometimes pthread_create block and never return.
>
> I have made a simple program (test.c) to reproduce the problem.
>
>> gcc test.c -lpthread -o test
>> ./test
> thread id=1
> thread id=2
> thread id=3
> thread id=4
> ........
> thread id=3736
>
>
> Sometimes pthread_create block after creating arround 10 threads,
> sometimes after creating arround 10000 threads or more.
You may have run into the pthread interlocking bug that I'm tracking down in
this thread on the cygwin-dev list:
http://www.cygwin.com/ml/cygwin-developers/2009-05/threads.html#00084
If you'd like to try building the cygwin DLL yourself from the CVS sources
with the attached patch applied, you may find it solves your problem; at least
for me it does. I've been running your test program while writing this email
and it's got as far as this:
thread id=1260546
thread id=1260547
... without a hiccup. Actually, now it's got as far as
thread id=2405875
by the time I diff'd the patch for you. (If you'd prefer, I could send you a
binary of the DLL built with the patch, off-list; let me know).
cheers,
DaveK
--------------030804020300020409010901
Content-Type: text/x-c;
name="asm-interlock.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="asm-interlock.diff"
Index: winsup/cygwin/winbase.h
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/winbase.h,v
retrieving revision 1.14
diff -p -u -r1.14 winbase.h
--- winsup/cygwin/winbase.h 12 Jul 2008 18:09:17 -0000 1.14
+++ winsup/cygwin/winbase.h 2 Jun 2009 10:06:17 -0000
@@ -38,21 +38,21 @@ ilockdecr (volatile long *m)
extern __inline__ long
ilockexch (volatile long *t, long v)
{
- register int __res;
+ register long __res __asm__ ("%eax") = *t;
__asm__ __volatile__ ("\n\
-1: lock cmpxchgl %3,(%1)\n\
+1: lock cmpxchgl %2,%1\n\
jne 1b\n\
- ": "=a" (__res), "=q" (t): "1" (t), "q" (v), "0" (*t): "cc");
+ ": "+a" (__res), "=m" (*t): "q" (v), "m" (*t) : "memory", "cc");
return __res;
}
extern __inline__ long
ilockcmpexch (volatile long *t, long v, long c)
{
- register int __res;
+ register long __res __asm ("%eax") = c;
__asm__ __volatile__ ("\n\
- lock cmpxchgl %3,(%1)\n\
- ": "=a" (__res), "=q" (t) : "1" (t), "q" (v), "0" (c): "cc");
+ lock cmpxchgl %2,%1\n\
+ ": "+a" (__res), "=m" (*t) : "q" (v), "m" (*t) : "memory", "cc");
return __res;
}
--------------030804020300020409010901
Content-Type: text/plain; charset=us-ascii
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
--------------030804020300020409010901--
- Raw text -