Bad codegen in pthread_mutex causing 100% cpu spin loop related to inline asm ilockcmpexchg

Christopher Faylor
Thu May 28 22:52:00 GMT 2009

On Thu, May 28, 2009 at 10:49:42PM +0100, Dave Korn wrote:
>Dave Korn wrote:
>>   This new version changes the approach to use an "m" constraint to refer
>> directly to the contents of *t, and not hope the compiler can infer the
>> relationship between the address of t in operand 2 and the content of t in
>> operand 1.  It requires rewriting the instruction template, and will generate
>> more different addressing modes than the original, which would only create
>> register-indirect addressing:
>> extern __inline__ long
>> ilockcmpexch (volatile long *t, long v, long c)
>> {
>>   register int __res;
>>   __asm__ __volatile__ ("\n\
>> 	lock cmpxchgl %2,%1\n\
>> 	": "=a" (__res), "+m" (*t) : "q" (v), "0" (c) : "memory", "cc");
>>   return __res;
>> }
>  Then I thought, why not go the whole hog and get rid of the matching
>constraints altogether by making __res an in/out operand and passing 'c' in
>it.  So I tried this:

I got these functions from some well-known source like linux, glibc,
uclibc or freebsd.  We can just go back to the same well and be assured
that we are getting something that is tested.


More information about the Cygwin-developers mailing list