Are the dl* functions thread-safe?

Are the dl* functions thread-safe?

Post by Lars J. A » Wed, 01 Apr 1998 04:00:00



  Hi,

Looking at the dlopen(), dlsym(), etc. functions, the dlerror() function
strikes me as far from thread-safe.  Is it just dlerror(), or are the
other dl*-functions also thread-unsafe?

  Lars J
--
The contents of this .signature file is fictitious. No similarity to actual
 .signature files, digital or hardcopy, is intended or should be inferred.


 
 
 

Are the dl* functions thread-safe?

Post by Joe Bu » Wed, 01 Apr 1998 04:00:00



> Looking at the dlopen(), dlsym(), etc. functions, the dlerror() function
> strikes me as far from thread-safe.  Is it just dlerror(), or are the
> other dl*-functions also thread-unsafe?

When people say "thread-safe" they generally mean that all the state of
the function is stored in a thread-specific way.  Clearly this is
impossible in the case of the dl* functions: there is only one executable
and it is linked with a specific set of shared libraries at any given
time.  So you would need to add your own locking if you want to use dl*
functions in multiple threads.  This is not a bug, and a reimplementation
isn't going to get rid of it.

--
-- Joe Buck
See my daughter: http://www.byoc.com/homepage/130481/molly.html
Boring semi-official web page:
                 http://www.synopsys.com/news/pubs/research/people/jbuck.html

 
 
 

Are the dl* functions thread-safe?

Post by Ulrich Dreppe » Wed, 01 Apr 1998 04:00:00



> When people say "thread-safe" they generally mean that all the state of
> the function is stored in a thread-specific way.  Clearly this is
> impossible in the case of the dl* functions: there is only one executable
> and it is linked with a specific set of shared libraries at any given
> time.  So you would need to add your own locking if you want to use dl*
> functions in multiple threads.  This is not a bug, and a reimplementation
> isn't going to get rid of it.

This is not really true.  The libdl.so in glibc 2.1 actually has no
such problem.  The dlopen/dlclose functions synchronize itself (must
be this way since they modify global data) and the error string is
stored in thread specific data.  So it is completely safe to call
these functions from threads.

-- Uli
---------------.      drepper at gnu.org  ,-.   1325 Chesapeake Terrace
Ulrich Drepper  \    ,-------------------'   \  Sunnyvale, CA 94089 USA
Cygnus Solutions `--' drepper at cygnus.com   `------------------------

 
 
 

1. Documentation for thread-safe network lookup functions.

Does anyone have a documentation link for the thread-safe network
configuration lookup functions? The ones I'm referring to include (from
AIX4.3.3's /usr/include/netdb.h):

extern int getnetbyaddr_r(in_addr_t net, int type, struct netent *netptr,
        struct netent_data *net_data);
extern int getnetbyname_r(const char *name, struct netent *netptr,
        struct netent_data *net_data);
extern int setnetent_r(int f, struct netent_data *net_data);
extern void endnetent_r(struct netent_data *net_data);
extern int getnetent_r(struct netent *net, struct netent_data *net_data);
extern int gethostbyname_r(const char *name, struct hostent *htent,
        struct hostent_data *ht_data);
extern int gethostbyaddr_r(char *addr, size_t len, int type,
        struct hostent *htent, struct hostent_data *ht_data);
extern int gethostent_r(struct hostent *htent, struct hostent_data
*ht_data);
extern void endhostent_r(struct hostent_data *ht_data);
extern void sethostent_r(int flag, struct hostent_data *ht_data);
extern int setservent_r(int f, struct servent_data *serv_data);
extern void endservent_r(struct servent_data *serv_data);
extern int getservent_r(struct servent *serv, struct servent_data
*serv_data);
extern int getservbyname_r(const char *name, const char *proto,
        struct servent *servptr, struct servent_data *serv_data);
extern int getservbyport_r(int port, const char *proto, struct servent
*servptr,        struct servent_data *serv_data);
extern int setprotoent_r(int f, struct protoent_data *proto_data);
extern void endprotoent_r(struct protoent_data *proto_data);
extern int getprotoent_r(struct protoent *proto,
        struct protoent_data *prot_data);
extern int getprotobyname_r(const char *name, struct protoent *protoptr,
        struct protoent_data *proto_data);
extern int getprotobynumber_r(int proto, struct protoent *protoptr,
         struct protoent_data *proto_data);
extern int setrpcent_r(int f, struct rpcent_data *rpc_data);
extern void endrpcent_r(struct rpcent_data *rpc_data);
extern int getrpcent_r(struct rpcent *rpcent, struct rpcent_data *rpc_data);
extern int getrpcbyname_r(const char *name, struct rpcent *rpcent,
                          struct rpcent_data *rpc_data);
extern int getrpcbynumber_r(int number, struct rpcent *rpcent,
                            struct rpcent_data *rpc_data);
extern int setnetgrent_r(char *, void **);
extern void endnetgrent_r(void **ptr);
extern int getnetgrent_r( char **, char **, char **, void **);
extern int innetgr_r(char *, char *, char *, char *, struct innetgr_data *);

--
John Muir
SDM Platform Software Design
NORTEL Networks

2. Lucent Tech. Mars Internal Modem

3. Thread-safe functions

4. yppasswd got hung

5. Thread-safe gethostby* functions in AIX 4.3.3.

6. FIPS and Win950B??

7. Using thread-safe C library functions.

8. uugetty troubles

9. Solaris 8 threads: If a routine is Async-Signal-Safe is it also thread Safe?

10. mmap, thread-safe, and signal-safe

11. Thread-safe and Signal-safe

12. List of non-thread-safe SunOS library functions?

13. need multi thread safe usleep() function