Subj : Re: redhat linux standard C library does not have pthread_mutex_trylock ??? To : comp.programming.threads From : Paul Pluzhnikov Date : Mon Feb 07 2005 08:11 am "David Schwartz" writes: > > - Is this a problem or a feathure of Linux? I think the reason e.g. pthread_mutex_lock() stub is defined in libc.so.6, while pthread_mutex_trylock() isn't, is that the former is needed by glibc itself for thread-safe operation. > You may > even be able to create a 'weakly-linked' pthread_mutex_trylock function such > that the real one, if present, will take over automatically. This is the best approach, and is trivially done: extern int pthread_mutex_trylock(pthread_mutex_t *) __attribute__((weak)); ... if (pthread_mutex_trylock) { pthread_mutex_trylock(&mtx); // call it only if linked // against libpthread } > > - What's the overhead of linking a single thread app with -lpthread > > There is no overhead on Linux, as I understand it. Oh there *is* overhead. It's not likely to be very significant in a properly-coded application, but an app that spins in a tight loop doing just pthread_mutex_lock()/unlock(), shows a factor of 10 slowdown when linked against libpthread on RedHat-6.2 (glibc-2.13) and a factor of 3 on RHEL-3u4 (glibc-2.3.2-95.30). Cheers, -- In order to understand recursion you must first understand recursion. Remove /-nsp/ for email. .