[freetds] threadsafe

ZIGLIO, Frediano, VF-IT Frediano.Ziglio at vodafone.com
Tue Aug 29 08:03:01 EDT 2006


> 
> On Wed, Aug 23, 2006 at 09:59:05PM +0200, Frediano Ziglio wrote:
> > I think you are right, if one don't want thread safety we shouldn't
> > check for thread-safe functions although nowadays threads are very
> > common so I don't suggest the use of this flag.
> 
> Hi Freddy, 
> 
> Common, but not ubiquitous.  Someone you know pretty well, 
> someone I know 
> very well, uses NetBSD 2.0.  At the moment I, er, he can't 
> compile because
> --disable-threadsafe stumbles.  See attached.  
> 
> The NetBSD kernel has threads, and its userland implement an 
> M-N threading
> model, but not every function is available, including some important 
> *_r functions.  I keep tring to compile FreeTDS with threads 
> with each new 
> version of NetBSD, but so far --disable-threadsafe is my best 
> friend.  Or 
> was.  :-(
> 
> As a db-lib and Perl programmer, I have no use for threads.  
> (Actually, 
> I have no use for them at all.  I think they're a terrible 
> idea that set
> computing back 30 years.)  So I'd be really glad to see this option 
> working again.  
> 
> Regards,
> 

I agree it should compile. But I didn't realized that it do not compile
where it compiled...
I think that it do not compile cause we added some configuration for
thread that cause some miss-detecting... I think the problem reside in
http://freetds.cvs.sourceforge.net/freetds/freetds/configure.ac?r1=1.8&r
2=1.10 change (mainly ACX_PTHREAD use). IMHO thread detect is quite
wrong currently... trying to extract m4 from configure.ac

...
if test $netdb_reentrant = yes; then
    AC_DEFINE(NETDB_REENTRANT, 1, [Define to 1 if the BSD-style netdb
interface is reentrant.])
fi
...
        ACX_PTHREAD
        AM_CFLAGS="$AM_CFLAGS $PTHREAD_CFLAGS"
        AC_SUBST(AM_CFLAGS)
        LIBS="$PTHREAD_LIBS $LIBS"
...
AC_CHECK_FUNCS([vsnprintf gettimeofday \
nl_langinfo locale_charset setenv putenv \
getuid getpwuid getpwuid_r fstat alarm \
gethrtime])
OLD_LIBS="$LIBS"
LIBS="$LIBS $NETWORK_LIBS"
AC_CHECK_FUNCS([inet_ntoa_r getipnodebyaddr getipnodebyname freehostent
\
getaddrinfo getnameinfo inet_ntop inet_pton \
gethostname sethostent_r gethostent_r])
LIBS="$OLD_LIBS"
AC_REPLACE_FUNCS([asprintf vasprintf atoll strtok_r readpassphrase \
strlcpy strlcat basename])
...
AC_MSG_CHECKING(threadsafety)
# Enable or disable thread safetiness
# This option is enabled by default because most OS's support it.
# A more sophisticated approach would be to set the default per-OS.
AC_ARG_ENABLE(threadsafe,
        AS_HELP_STRING([--disable-threadsafe], [disable calls to
threadsafe fuctions e.g.,gethostbyname_r ]),
        [use_threadsafe=$enableval], [use_threadsafe=yes])

if test "$enable_threadsafe" != "no" ; then
        CPPFLAGS="$CPPFLAGS -D_REENTRANT -D_THREAD_SAFE"
        AC_MSG_RESULT(enabled)
else
        AC_MSG_RESULT(disabled)
fi
AM_CONDITIONAL(ENABLE_THREADSAFE, test "$enable_threadsafe" != "no")

# we don't need to check netdb functions if they are already threadsafe
if test $netdb_reentrant != yes; then
        AC_caolan_FUNC_WHICH_GETHOSTBYNAME_R
        AC_raf_FUNC_WHICH_GETSERVBYNAME_R
        AC_tds_FUNC_WHICH_GETHOSTBYADDR_R
fi
AC_tds_FUNC_WHICH_GETPWUID_R
AC_tds_FUNC_WHICH_LOCALTIME_R

# easy test for pthread (no library, only mutex support)
AC_TRY_LINK([#include <pthread.h>
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;],
[pthread_mutex_lock(&mutex);
pthread_mutex_unlock(&mutex)], AC_DEFINE(TDS_HAVE_PTHREAD_MUTEX, 1,
[Define if you have pthread with mutex support]))
...

Some problems
- thread support is tested with ACX_PTHREAD even if --disable-threadsafe
is specified
- PTHREAD_CC and PTHREAD_CFLAGS are not used by all configure tests...
should them be used and ACX_PTHREAD called ASAP ?
- we test for getXXXbyXXX_r only if netdb_reentrant is no but in
src/tds/threadsafe.c we require _r functions (why did the code work
before ACX_PTHREAD call?)
- we test for mutex even if --disable-threadsafe is specified (and with
no flags)..

freddy77




More information about the FreeTDS mailing list