Samuel Tardieu <[EMAIL PROTECTED]> writes: > #include <pthread.h> > > static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; > static int acquires_count = 0; > > int > trylock() > { > int res; > > res = pthread_mutex_trylock(&mutex); > if (res == 0) > ++acquires_count; > > return res; > } > > trylock: > subl $12, %esp > movl $mutex, (%esp) > call pthread_mutex_trylock > movl acquires_count, %edx > cmpl $1, %eax > adcl $0, %edx > movl %edx, acquires_count > addl $12, %esp > ret
By the way, since this is getting play on LKML and no doubt other places: This optimization (or pessimization, depending) is not new. gcc 4.1 does the same thing. The code has been in there since at least gcc 3.4, though I didn't build gcc 3.4 to test what happened. Code like needs to use volatile or explicit memory barriers. Ian