Subj : Re: redhat linux standard C library does not have pthread_mutex_trylock ??? To : comp.programming.threads From : David Schwartz Date : Mon Feb 07 2005 07:05 am wrote in message news:1107786859.633834.238160@c13g2000cwb.googlegroups.com... > I have developed a general library that is MT safe and used standard > Pthread calls, this library can be used in both MT programs (link with > -lpthread) or single thread programs (without > -lpthread, the standard C library provided the dummy implementation for > the pthread functions), this works fine on Solaris; however, when we > are porting the system onto Linux (redhat), we got a problem because > the standard C library does not have pthread_mutex_trylock defined > (while all the other pthread_mutex_xxx functions are defined), this has > forced us to link -lpthread with all the programs, even though the > program is only meant to be single thread application. This is quite true. > - Does someone know such a list of pthread functions not defined in the > standard C library? You really can't rely on any of them, I'm afraid to say. > - Is this a problem or a feathure of Linux? (I'm quite new to Linux > development) I tried several versions they all have this same issue. If > it's a problem, what's the well-known solution? It's the absence of a questionable feature. You could write your own 'pthread_mutex_trylock' function that checks if you're single-threaded or multi-threaded and if multi-threaded, manually looks up the symbol. 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. I'm not totally sure. > - What's the overhead of linking a single thread app with -lpthread > (thus forced it to be MT even though there's only one user thread)? There is no overhead on Linux, as I understand it. Linking the application doesn't fort it to be multi-threaded, creating threads does. > - Does Linux encourage people to develop MT applications? Linux encourages people to develop libraries and applications that use MT-safe low-level functions. DS .