Re: thread safety tests

From: Jan Wieck <JanWieck(at)Yahoo(dot)com>
To: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: thread safety tests
Date: 2004-06-09 16:06:57
Message-ID: 40C735A1.90104@Yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 6/9/2004 11:45 AM, Bruce Momjian wrote:

> Jan Wieck wrote:
>> The problem is that if your thread-safety tests fail, there is no way to
>> build libpq with -pthread and -DREENTRANT or whatever is required on
>> that platform. On Solaris this results in errno being defined as
>>
>> extern int errno;
>>
>> as supposed to
>>
>> #define errno *(errno())
>>
>> which makes libpq on Solaris completely useless for every program that
>> uses threads for "something". There is still value in compiling it with
>> thread support compiler flags, even if it will not result in a thread
>> safe libpq.
>
> Well, first we should find out how to get the thread test to pass for
> that patform, but for cases where we can't (FreeBSD doesn't have
> getpwuid_r(), we are stuck. (That might be your Solaris problem as
> well.)

There is no problem with thread safety on Solaris. The configure script
for 7.4.2 is broken for it, leading to a broken libpq when using
--enable-thread-safey.

>
> I looked over the code and the only place getpwuid_r (through
> pqGetpwuid) is used is in libpq to look up the default username based on
> the euid for the connection to the backend. Unfortunately, I can't find
> any other way to do such a lookup in a thread-safe manner unless we do a
> system() or lock/read /etc/passwd ourselves, both of which are ugly.
>
> I can't imagine how some OS's cannot give us a thread-safe way to do
> this.
>
> When FreeBSD can't enable threads in 7.5, folks are going to be upset.
> In 7.4 we allowed it by having our own C code lock/copy the passwd
> structure, but someone pointed out that calls to getpwuid() in other
> places in the client code don't have such locking, so it would not work,
> so it was removed for 7.5.

I disagree that all or nothing is a good strategy. What you have changed
this to is to deny using PostgreSQL from multithreaded applications on
platforms that have no getpwuid_r() altogether, if their platform
happens to require any thread special compiler options for libpq to work
in general.

Take Slony as an example. It is multithreaded, and we aren't happy that
we have to guard the pg_connect() call with a mutex against multiple
concurrent calls. But since our connections are of long living nature
this is no problem. And nowhere else in the entire code is any call to
getpwuid() or anything else. So we have the situation under control. But
I really don't want to tell people in the build instructions that they
have to edit libpq's Makefile because PostgreSQL's ./configure script is
too restrictive.

And just to make your day, your tests for thread safety are incomplete.
The reason why we use a mutex now on all platforms, thread safe or not,
is because in the event you have a kerberos lib available (which is not
thread safe), pg_connect() can crash wether you use kerberos or not. So
I think when compiling for --enable-thread-safe we should disable
kerberos in libpq, right?

Jan

--
#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#================================================== JanWieck(at)Yahoo(dot)com #

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Alvaro Herrera 2004-06-09 16:07:17 pg_dumpall.c missing include time.h?
Previous Message Greg Stark 2004-06-09 15:49:12 Re: Assignment to array elements