Thread: Re: [HACKERS] ECPG thread-safety

Re: [HACKERS] ECPG thread-safety

From
Bruce Momjian
Date:
I have developed the following configure thread test based on your
information.  I have opted for a simple check for pthread.h, and we can
then fill in any additional library flags needed for various OS's.

---------------------------------------------------------------------------

Shridhar Daithankar wrote:
> On Friday 28 March 2003 21:30, you wrote:
> > Would someone take those patches and hunt around for proper 'configure'
> > tests?  I can do the configure coding, but I don't know what tests to
> > make.
> >
> >     http://services.csl.co.uk/postgresql/
>
> I also need configure tests for thread for one of my other application and
> don't know how to put them. So I have left those as additional ldflags
> options to users.
>
> I suggest we somehow test following config to start with
>
> 1) Linuxthreads on linux
> Threads are usually installed in /usr/ So pthread.h and -lpthread should work
> on most setups.
>
> 2) Native freeBSD threads
> pthread.h in /usr/include and lc_r
>
> 3)linuxthreads on freeBSD, ports collection
> /usr/local/include/pthreads/linuxthreads/pthread.h
> /usr/local/lib/libpthread.so
>
> For testing the library, I think it is enough to init an thread attr. like
> pthread_init_attr, that should be enough to test header and library.
>
> I don't how we are going to let people specify thread implementation where
> there are multiple thread libraries are available .e.g. freeBSD.
>
> HTH
>
>  Shridhar
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
>     (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)
>

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073
Index: configure.in
===================================================================
RCS file: /cvsroot/pgsql-server/configure.in,v
retrieving revision 1.253
diff -c -c -r1.253 configure.in
*** configure.in    22 May 2003 16:39:28 -0000    1.253
--- configure.in    26 May 2003 16:57:51 -0000
***************
*** 506,511 ****
--- 506,514 ----
                [  --without-zlib          do not use Zlib])


+ #
+ # Elf
+ #

  # Assume system is ELF if it predefines __ELF__ as 1,
  # otherwise believe host_os based default.
***************
*** 527,533 ****
--- 530,557 ----
  fi])
  AC_SUBST(ELF_SYS)

+ #
+ # Pthreads
+ #

+ AC_CHECK_HEADER(pthread.h,
+     [AC_DEFINE(HAVE_THREADS, 1, [Define to 1 if you have the threads interface.])])
+ if test ! -z "$HAVE_THREADS"
+ then
+     case $host_os in
+         # BSD/OS and NetBSD require no special libraries
+         netbsd*|bsdi*) THREAD_LIBS="" ;;
+         freebsd*) THREAD_LIBS="-lc_r" ;;
+         linux*) THREAD_LIBS="-lpthread" ;;
+     # other operating systems might fail because they have pthread.h but need
+     # special libs we don't know about yet.
+     esac
+ fi
+ AC_SUBST(THREAD_LIBS)
+
+ #
+ # Assignments
+ #

  CPPFLAGS="$CPPFLAGS $INCLUDES"
  LDFLAGS="$LDFLAGS $LIBDIRS"
Index: src/Makefile.global.in
===================================================================
RCS file: /cvsroot/pgsql-server/src/Makefile.global.in,v
retrieving revision 1.162
diff -c -c -r1.162 Makefile.global.in
*** src/Makefile.global.in    11 May 2003 20:50:53 -0000    1.162
--- src/Makefile.global.in    26 May 2003 16:57:53 -0000
***************
*** 152,157 ****
--- 152,159 ----
  TK_LIB_SPEC        = @TK_LIB_SPEC@
  TK_XINCLUDES        = @TK_XINCLUDES@

+ THREAD_LIBS        = @THREAD_LIBS@
+
  have_docbook    = @have_docbook@
  DOCBOOKSTYLE    = @DOCBOOKSTYLE@
  COLLATEINDEX    = @COLLATEINDEX@
Index: src/include/pg_config.h.in
===================================================================
RCS file: /cvsroot/pgsql-server/src/include/pg_config.h.in,v
retrieving revision 1.47
diff -c -c -r1.47 pg_config.h.in
*** src/include/pg_config.h.in    22 May 2003 16:39:30 -0000    1.47
--- src/include/pg_config.h.in    26 May 2003 16:57:57 -0000
***************
*** 465,470 ****
--- 465,473 ----
  /* Define to 1 if you have the <termios.h> header file. */
  #undef HAVE_TERMIOS_H

+ /* Define to 1 if you have the <pthread.h> header file. */
+ #undef HAVE_THREADS
+
  /* Define to 1 if your `struct tm' has `tm_zone'. Deprecated, use
     `HAVE_STRUCT_TM_TM_ZONE' instead. */
  #undef HAVE_TM_ZONE

Re: [HACKERS] ECPG thread-safety

From
Tom Lane
Date:
Bruce Momjian <pgman@candle.pha.pa.us> writes:
> diff -c -c -r1.47 pg_config.h.in
> *** src/include/pg_config.h.in    22 May 2003 16:39:30 -0000    1.47
> --- src/include/pg_config.h.in    26 May 2003 16:57:57 -0000

Bruce, you do realize that you're not supposed to hand-edit
pg_config.h.in anymore?  Use autoheader to build it from configure.in.

            regards, tom lane

Re: [HACKERS] ECPG thread-safety

From
Bruce Momjian
Date:
Tom Lane wrote:
> Bruce Momjian <pgman@candle.pha.pa.us> writes:
> > diff -c -c -r1.47 pg_config.h.in
> > *** src/include/pg_config.h.in    22 May 2003 16:39:30 -0000    1.47
> > --- src/include/pg_config.h.in    26 May 2003 16:57:57 -0000
>
> Bruce, you do realize that you're not supposed to hand-edit
> pg_config.h.in anymore?  Use autoheader to build it from configure.in.

You mentioned that recently, and I wasn't sure exactly how you did it,
and figured I would research it later.

I got it working and here is the updated patch --- thanks.

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073
Index: configure.in
===================================================================
RCS file: /cvsroot/pgsql-server/configure.in,v
retrieving revision 1.253
diff -c -c -r1.253 configure.in
*** configure.in    22 May 2003 16:39:28 -0000    1.253
--- configure.in    26 May 2003 18:19:14 -0000
***************
*** 506,511 ****
--- 506,514 ----
                [  --without-zlib          do not use Zlib])


+ #
+ # Elf
+ #

  # Assume system is ELF if it predefines __ELF__ as 1,
  # otherwise believe host_os based default.
***************
*** 527,533 ****
--- 530,560 ----
  fi])
  AC_SUBST(ELF_SYS)

+ #
+ # Pthreads
+ #

+ AC_CHECK_HEADER(pthread.h,
+     [AC_DEFINE(HAVE_THREADS, 1, [Define to 1 if you have the threads interface.])])
+ if test ! -z "$HAVE_THREADS"
+ then
+     case $host_os in
+         # BSD/OS and NetBSD require no special libraries or flags
+         netbsd*|bsdi*) ;;
+         freebsd4*) THREAD_CFLAGS="-pthread" ;;
+         freebsd*) THREAD_LIBS="-lc_r" ;;
+         linux*) THREAD_LIBS="-lpthread"
+             THREAD_CFLAGS="-D_REENTRANT" ;;
+     # other operating systems might fail because they have pthread.h but need
+     # special libs we don't know about yet.
+     esac
+ fi
+ AC_SUBST(THREAD_LIBS)
+ AC_SUBST(THREAD_CFLAGS)
+
+ #
+ # Assignments
+ #

  CPPFLAGS="$CPPFLAGS $INCLUDES"
  LDFLAGS="$LDFLAGS $LIBDIRS"
Index: src/Makefile.global.in
===================================================================
RCS file: /cvsroot/pgsql-server/src/Makefile.global.in,v
retrieving revision 1.162
diff -c -c -r1.162 Makefile.global.in
*** src/Makefile.global.in    11 May 2003 20:50:53 -0000    1.162
--- src/Makefile.global.in    26 May 2003 18:19:15 -0000
***************
*** 152,157 ****
--- 152,160 ----
  TK_LIB_SPEC        = @TK_LIB_SPEC@
  TK_XINCLUDES        = @TK_XINCLUDES@

+ THREAD_CFLAGS        = @THREAD_CFLAGS@
+ THREAD_LIBS        = @THREAD_LIBS@
+
  have_docbook    = @have_docbook@
  DOCBOOKSTYLE    = @DOCBOOKSTYLE@
  COLLATEINDEX    = @COLLATEINDEX@
Index: src/include/pg_config.h.in
===================================================================
RCS file: /cvsroot/pgsql-server/src/include/pg_config.h.in,v
retrieving revision 1.47
diff -c -c -r1.47 pg_config.h.in
*** src/include/pg_config.h.in    22 May 2003 16:39:30 -0000    1.47
--- src/include/pg_config.h.in    26 May 2003 18:19:16 -0000
***************
*** 465,470 ****
--- 465,473 ----
  /* Define to 1 if you have the <termios.h> header file. */
  #undef HAVE_TERMIOS_H

+ /* Define to 1 if you have the threads interface. */
+ #undef HAVE_THREADS
+
  /* Define to 1 if your `struct tm' has `tm_zone'. Deprecated, use
     `HAVE_STRUCT_TM_TM_ZONE' instead. */
  #undef HAVE_TM_ZONE

Re: [HACKERS] ECPG thread-safety

From
Tom Lane
Date:
Bruce Momjian <pgman@candle.pha.pa.us> writes:
>> Bruce, you do realize that you're not supposed to hand-edit
>> pg_config.h.in anymore?  Use autoheader to build it from configure.in.

> You mentioned that recently, and I wasn't sure exactly how you did it,
> and figured I would research it later.

You just run autoheader immediately after autoconf --- it's no different
from building configure from configure.in.

            regards, tom lane

Re: [HACKERS] ECPG thread-safety

From
Bruce Momjian
Date:
Tom Lane wrote:
> Bruce Momjian <pgman@candle.pha.pa.us> writes:
> >> Bruce, you do realize that you're not supposed to hand-edit
> >> pg_config.h.in anymore?  Use autoheader to build it from configure.in.
>
> > You mentioned that recently, and I wasn't sure exactly how you did it,
> > and figured I would research it later.
>
> You just run autoheader immediately after autoconf --- it's no different
> from building configure from configure.in.
>

Yes, I see now.  I thought autoheader was for generating include
dependencies, actually.
--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073