Re: Thread Safety of ODBC Driver

From: "Jason Koeninger" <jkoenin(at)jjcc(dot)com>
To: "Hiroshi Inoue" <Inoue(at)tpf(dot)co(dot)jp>
Cc: "pgsql-odbc(at)postgresql(dot)org" <pgsql-odbc(at)postgresql(dot)org>
Subject: Re: Thread Safety of ODBC Driver
Date: 2002-09-07 01:32:16
Message-ID: 20020907013838.98AC4475BEC@postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-odbc

Here's a list of the issues I found. Since you've dealt with the statics,
I won't worry about those.

connection.c: Uses strtok. Could convert to strtok_r. On FreeBSD,
I used strsep.

convert.c: localtime used in copy_and_convert_field and
copy_statement_with_parameters. Use localtime_r and create
another struct tm to use as the extra argument.

environ.c: The "conns" global at the start of the file could be a
problem. Looks like the only reason it's used is to commit all
connections on a single HENV at once if SQLTransact receives
a NULL HDBC. If it's necessary that the array exist, you'll have
to serialize access somehow.

execute.c: Uses the conns global in PGAPI_Transact.

gpps.c: The Unix implementation of Windows INI files has a
couple functions I'm not as familiar with, but I think they may be
a problem. getpwuid and getuid. I believe they return pointers
to statics, don't they?

misc.c: Also has some getpwuid and getuid calls. mylog and
qlog probably need to be serialized, but they shouldn't cause a
crash.

socket.c: Uses gethostbyname. Some platforms have a
gethostbyname_r, but the implementations vary. I know in my
class libraries, I have a different implementation across
Linux, Solaris, FreeBSD, Windows, and OS/2. On FreeBSD,
you can use mutexes to serialize gethostbyname or use the
function getipnodebyname. The others either have a gethostbyname
that returns thread local storage or a gethostbyname_r
variation.

The problem with these fixes is that, at least in FreeBSD, you
have to compile with the -pthread option to get some of the
normal C library functions to work safely in a threaded environment.
Some of the functions are also only defined in libc_r so some of
these fixes may require precompiler directives and makefile changes
if you want a thread-safe driver.

Let me know if there's anything I can do to help. I'm also going
to be looking into modifying the code to let me set the transaction
isolation level to serializable. If you have any recommendations
or preferences in that area, please let me know.

Best Regards,

Jason Koeninger
J&J Computer Consulting
http://www.jjcc.com

On Sat, 7 Sep 2002 07:31:08 +0900, Hiroshi Inoue wrote:

>> -----Original Message-----
>> From: Jason Koeninger
>>
>> I was surprised to find a message in the archive indicating that the
>> PostgreSQL ODBC driver was not thread safe. After running through
>> the source, I was able to confirm that the driver indeed isn't thread
>> safe.
>>
>> Anyway, I'm curious if anyone is working on making the driver
>> thread safe.
>
>It's on my personal TODO but I haven't had much time to
>develop psqlodbc recently.
>
>> I noticed that some work has been done on the driver provided with
>> unixODBC (localtime and localtime_r ifdefs), but it still misses
>> a few things I
>> found on a quick read through the source.
>
>As for static variables, I have removed most of them in my local source.
>As for non thread-safe functions, please point out how to change them.
>Maybe I would be able to reflect the change to CVS.
>
>regards,
>Hiroshi Inoue
>
>

Browse pgsql-odbc by date

  From Date Subject
Next Message Allan 2002-09-08 13:15:30 unsubscribe
Previous Message Hiroshi Inoue 2002-09-06 22:31:08 Re: Thread Safety of ODBC Driver