Re: thread_test.c problems

Поиск
Список
Период
Сортировка
От Bruce Momjian
Тема Re: thread_test.c problems
Дата
Msg-id 200404050128.i351S5R20232@candle.pha.pa.us
обсуждение исходный текст
Ответ на Re: thread_test.c problems  (<wespvp@syntegra.com>)
Ответы Re: thread_test.c problems  (<wespvp@syntegra.com>)
Список pgsql-general
wespvp@syntegra.com wrote:
> Add this to your template/$port file:
>
> STRERROR_THREADSAFE=yes
> GETPWUID_THREADSAFE=yes
> GETHOSTBYNAME_THREADSAFE=no
>
> [g4:src/tools/thread] wp% ./thread_test
> Make sure you have added any needed 'THREAD_CPPFLAGS' and 'THREAD_LIBS'
> defines to your template/$port file before compiling this program.
>
> Add this to your template/$port file:
>
> STRERROR_THREADSAFE=yes
> GETPWUID_THREADSAFE=yes
> GETHOSTBYNAME_THREADSAFE=yes
>
>
> It returns mostly 'yes' for all three, but sometimes returns 'no' for the
> last one.  I get the same conflicting results whether I run with one or two
> CPU's enabled.
>

OK, I know the cause of this.  The problem is that sometimes hostnames
don't resolve, and the bigger problem is that it requires an internet
connection to run the tests.  The attached patch tests for 'localhost'
and your local hostname, so it should work reliably.


> Similarly, the 7.4.2 release is showing:
>
> % ./thread_test
> Make sure you have added any needed 'THREAD_CPPFLAGS' and 'THREAD_LIBS'
> defines to your template/$port file before compiling this program.
>
> All your non-*_r functions are thread-safe.
> Add this to your template/$port file:
>
> NEED_REENTRANT_FUNCS=no
>
>
> % ./thread_test
> Make sure you have added any needed 'THREAD_CPPFLAGS' and 'THREAD_LIBS'
> defines to your template/$port file before compiling this program.
>
> Your gethostbyname() is _not_ thread-safe
> Not all non-*_r functions are thread-safe.
> Add this to your template/$port file:
>
> NEED_REENTRANT_FUNCS=yes
>
>
>
> I assume the safe bet is GETHOSTBYNAME_THREADSAFE=no for the tip and
> NEED_REENTRANT_FUNCS=yes for 7.4.2?  Can I rely on the other two being
> 'yes', or should they be set to 'no' also?

Yes, that is the safe bet on 7.4.X.  7.5 will use individual entries for
each function, and in fact we might have this all merged into configure
by then anyway.


>
> Based on the linux template and the output of thread_test, I have set up the
> darwin template and compiled the CVS tip code on Mac OS X 10.3.3 with:
>
>
>
> # Apple's cpp-precomp seems a tad broken, so don't use it
> # (Note: on OS X before 10.2, you might need -traditional-cpp instead)
> #CC="$CC -no-cpp-precomp"
>
> # Select appropriate semaphore support
> USE_NAMED_POSIX_SEMAPHORES=1
>
> # tools/thread/thread_test must be run
> THREAD_SUPPORT=yes
> THREAD_CPPFLAGS="-D_REENTRANT -D_THREAD_SAFE -D_POSIX_PTHREAD_SEMANTICS"
> THREAD_LIBS="-lpthread"
>
> STRERROR_THREADSAFE=yes
> GETPWUID_THREADSAFE=yes
> GETHOSTBYNAME_THREADSAFE=no
>
> #NEED_REENTRANT_FUNCS=yes
>
>
>
>
> I commented out the 'CC="$CC -no-cpp-precomp"' line and did not get any
> compile errors.  Mac OS X 10.3.3 uses GCC 3.3.  I know something changed
> between Mac OS X 10.2 and 10.3 regarding precomp (they also upgraded from
> gcc 2.96 to 3.3).  It seems to compile ok on 10.3 regardless of the setting
> of this parameter, so unless it is important to have it enabled when
> possible, it is probably best to leave it off for backwards compatibility?
>
> I also added all of the thread lines starting with the comment '#
> tools/thread/thread_test must be run' based on the output of thread_test.
> The released PostgreSQL 7.4.2 says I should use 'NEED_REENTRANT_FUNCS=yes'.

Yes, in 7.4.X, you only need that single entry.

Thanks for the testing.

--
  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: src/tools/thread/thread_test.c
===================================================================
RCS file: /cvsroot/pgsql-server/src/tools/thread/thread_test.c,v
retrieving revision 1.10
diff -c -c -r1.10 thread_test.c
*** src/tools/thread/thread_test.c    4 Apr 2004 17:23:54 -0000    1.10
--- src/tools/thread/thread_test.c    5 Apr 2004 01:22:04 -0000
***************
*** 35,40 ****
--- 35,42 ----
  void func_call_1(void);
  void func_call_2(void);

+ char myhostname[MAXHOSTNAMELEN];
+
  int errno1_set = 0;
  int errno2_set = 0;

***************
*** 61,66 ****
--- 63,74 ----
              return 1;
      }

+     if (gethostname(myhostname, MAXHOSTNAMELEN) != 0)
+     {
+             fprintf(stderr, "can not get local hostname, exiting\n");
+             exit(1);
+     }
+
      printf("\
  Make sure you have added any needed 'THREAD_CPPFLAGS' and 'THREAD_LIBS'\n\
  defines to your template/$port file before compiling this program.\n\n"
***************
*** 128,135 ****
          passwd_p1 = NULL;    /* force thread-safe failure report */
      }

!     hostent_p1 = gethostbyname("www.yahoo.com");
!     p = gethostbyname("www.weather.com");
      if (hostent_p1 != p)
      {
          printf("Your gethostbyname() changes the static memory area between calls\n");
--- 136,144 ----
          passwd_p1 = NULL;    /* force thread-safe failure report */
      }

!     /* threads do this in opposite order */
!     hostent_p1 = gethostbyname(myhostname);
!     p = gethostbyname("localhost");
      if (hostent_p1 != p)
      {
          printf("Your gethostbyname() changes the static memory area between calls\n");
***************
*** 174,181 ****
          passwd_p2 = NULL;    /* force thread-safe failure report */
      }

!     hostent_p2 = gethostbyname("www.google.com");
!     p = gethostbyname("www.postgresql.org");
      if (hostent_p2 != p)
      {
          printf("Your gethostbyname() changes the static memory area between calls\n");
--- 183,191 ----
          passwd_p2 = NULL;    /* force thread-safe failure report */
      }

!     /* threads do this in opposite order */
!     hostent_p2 = gethostbyname("localhost");
!     p = gethostbyname(myhostname);
      if (hostent_p2 != p)
      {
          printf("Your gethostbyname() changes the static memory area between calls\n");

В списке pgsql-general по дате отправления:

Предыдущее
От: Stephan Szabo
Дата:
Сообщение: Re: RPM init-script: Why the locale setting?
Следующее
От: Tom Lane
Дата:
Сообщение: Re: thread_test.c problems