Re: Unixware Patch (Was: Re: Beta2 Tag'd and Bundled ...)

Поиск
Список
Период
Сортировка
От Bruce Momjian
Тема Re: Unixware Patch (Was: Re: Beta2 Tag'd and Bundled ...)
Дата
Msg-id 200309031936.h83Jar417879@candle.pha.pa.us
обсуждение исходный текст
Ответ на Re: Unixware Patch (Was: Re: Beta2 Tag'd and Bundled ...)  (ohp@pyrenet.fr)
Ответы Re: Unixware Patch (Was: Re: Beta2 Tag'd and Bundled ...)  (Larry Rosenman <ler@lerctr.org>)
Re: Unixware Patch (Was: Re: Beta2 Tag'd and Bundled ...)  (Kurt Roeckx <Q@ping.be>)
Re: Unixware Patch (Was: Re: Beta2 Tag'd and Bundled ...)  (Philip Yarra <philip@utiba.com>)
Список pgsql-hackers
ohp@pyrenet.fr wrote:
> > Olivier PRENANT wrote:
> > > >> It's ok to assume thread-safety, as the SCO developer (Kean Johnston)
> > > >> asked the threads guys, and he said that the libc stuff is
> > > >> thread-safe so they don't have to have 2 different versions in libc.
> > > >
> > > If any one can write a program that can prove anything (I can't), I'm
> > > willing to test it here on a bi-pro (bi PIII and bi-XEON with JT
> > > enabled) running uw713.
> > > Maybe it will end the discussion and make a point in either way. So that
> > > we (you?) can move on with the other unixware patches.
> >
> > You don't need a SMP machine to test threads.  You just need one thread
> > to do the function call, then another to do the function call and see if
> > the two pointers are different.  They calls don't have to happen at the
> > same time.  Ideally you could make call in the two threads with
> > different arguments, then after both calls are completed, test that the
> > two static areas have the proper _different_ values.
> >
> >
> Ok, I don't know much about threads; would you write a simple program for
> us to test?

OK, done, and attached.  It is also now in CVS as
src/tools/test_thread_funcs.c.

In hindsight, I should have done this long ago.  However, it only tests
the thread-safety of functions.  It does not completely test your threading
capability.

I would like every operating system that supports thread-safety to run
this program and report back the results.

--
  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
/*-------------------------------------------------------------------------
 *
 * test_thread_funcs.c
 *      libc thread test program
 *
 * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
 * Portions Copyright (c) 1994, Regents of the University of California
 *
 *    $Header: /cvsroot/pgsql-server/src/tools/test_thread_funcs.c,v 1.2 2003/09/03 19:36:31 momjian Exp $
 *
 *    This program tests to see if your standard libc functions use
 *    pthread_setspecific()/pthread_getspecific() to be thread-safe.
 *    See src/port/thread.c for more details.
 *
 *    This program first tests to see if each function returns a constant
 *    memory pointer within the same thread, then, assuming it does, tests
 *    to see if the pointers are different for different threads.  If they
 *    are, the function is thread-safe.
 *
 *    This program must be compiled with the thread flags required by your
 *    operating system.  See src/template for the appropriate flags, if any.
 *
 *-------------------------------------------------------------------------
 */


#include <pthread.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <netdb.h>
#include <sys/types.h>
#include <pwd.h>
#include <string.h>
#include <errno.h>

void func_call_1(void);
void func_call_2(void);

struct hostent *hostent_p1;
struct hostent *hostent_p2;

struct passwd *passwd_p1;
struct passwd *passwd_p2;

char *strerror_p1;
char *strerror_p2;

int main(int argc, char *argv[])
{
    pthread_t        thread1,
                    thread2;

    if (argc > 1)
    {
            fprintf(stderr, "Usage: %s\n", argv[0]);
            return 1;
    }

    pthread_create(&thread1, NULL, (void *) func_call_1, NULL);
    pthread_create(&thread2, NULL, (void *) func_call_2, NULL);
    pthread_join(thread1, NULL);
    pthread_join(thread2, NULL);

    if (hostent_p1 == hostent_p2)
        printf("Your gethostbyname() is _not_ thread-safe\n");
    if (passwd_p1 == passwd_p2)
        printf("Your getpwuid() is _not_ thread-safe\n");
    if (strerror_p1 == strerror_p2)
        printf("Your strerror() is _not_ thread-safe\n");

    if (hostent_p1 != hostent_p2 &&
        passwd_p1 != passwd_p2 &&
        strerror_p1 != strerror_p2)
        printf("Your functions are all thread-safe\n");
    else
        printf("Your functions are _not_ all thread-safe\n");

    return 0;
}

void func_call_1(void) {
    void *p;

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

    passwd_p1 = getpwuid(0);
    p = getpwuid(1);
    if (passwd_p1 != p)
    {
        printf("Your getpwuid() changes the static memory area between calls\n");
        passwd_p1 = NULL;    /* force thread-safe failure report */
    }

    strerror_p1 = strerror(EACCES);
    /*
     *    If strerror() uses sys_errlist, the pointer might change for different
     *    errno values, so we don't check to see if it varies within the thread.
     */
}


void func_call_2(void) {
    void *p;

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

    passwd_p2 = getpwuid(2);
    p = getpwuid(3);
    if (passwd_p2 != p)
    {
        printf("Your getpwuid() changes the static memory area between calls\n");
        passwd_p2 = NULL;    /* force thread-safe failure report */
    }

    strerror_p2 = strerror(EINVAL);
    /*
     *    If strerror() uses sys_errlist, the pointer might change for different
     *    errno values, so we don't check to see if it varies within the thread.
     */
}

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

Предыдущее
От: Samuel A Horwitz
Дата:
Сообщение: Re: elog.c comiple problem on AIX 4.2.1
Следующее
От: Peter Eisentraut
Дата:
Сообщение: Re: testing for usable C compiler