postgresql/src/test/thread
Tom Lane 69ae9dcb44 Ensure link commands list *.o files before LDFLAGS.
It's important for link commands to list *.o input files before -l
switches for libraries, as library code may not get pulled into the link
unless referenced by an earlier command-line entry.  This is certainly
necessary for static libraries (.a style).  Apparently on some platforms
it is also necessary for shared libraries, as reported by Donald Dong.

We often put -l switches for within-tree libraries into LDFLAGS, meaning
that link commands that list *.o files after LDFLAGS are hazardous.
Most of our link commands got this right, but a few did not.  In
particular, places that relied on gmake's default implicit link rule
failed, because that puts LDFLAGS first.  Fix that by overriding the
built-in rule with our own.  The implicit link rules in
src/makefiles/Makefile.* for single-.o-file shared libraries mostly
got this wrong too, so fix them.  I also changed the link rules for the
backend and a couple of other places for consistency, even though they
are not (currently) at risk because they aren't adding any -l switches
to LDFLAGS.

Arguably, the real problem here is that we're abusing LDFLAGS by
putting -l switches in it and we should stop doing that.  But changing
that would be quite invasive, so I'm not eager to do so.

Perhaps this is a candidate for back-patching, but so far it seems
that problems can only be exhibited in test code we don't normally
build, and at least some of the problems are new in HEAD anyway.
So I'll refrain for now.

Donald Dong and Tom Lane

Discussion: https://postgr.es/m/CAKABAquXn-BF-vBeRZxhzvPyfMqgGuc74p8BmQZyCFDpyROBJQ@mail.gmail.com
2019-01-02 13:57:54 -05:00
..
.gitignore Fix up .gitignore and cleanup actions in some src/test/ subdirectories. 2015-04-24 17:13:06 -04:00
Makefile Ensure link commands list *.o files before LDFLAGS. 2019-01-02 13:57:54 -05:00
README Remove dependency on wsock32.lib in favor of ws2_32 2014-07-15 14:18:39 +02:00
thread_test.c Update copyright for 2019 2019-01-02 12:44:25 -05:00

README

src/test/thread/README

Threading
=========

This program is run by configure to determine if threading is
properly supported on the platform.

You can run the program manually to see details, which shows if your
native libc functions are thread-safe, or if we use *_r functions or
thread locking.

To use this program manually, you must:

	o run "configure"
	o compile the main source tree
	o compile and run this program

If your platform requires special thread flags that are not tested by
/config/acx_pthread.m4, add PTHREAD_CFLAGS and PTHREAD_LIBS defines to
your template/${port} file.

Windows Systems
===============

Windows systems do not vary in their thread-safeness in the same way that
other systems might, nor do they generally have pthreads installed, hence
on Windows this test is skipped by the configure program (pthreads is
required by the test program, but not PostgreSQL itself). If you do wish
to test your system however, you can do so as follows:

1) Install pthreads in you Mingw/Msys environment. You can download pthreads
   from ftp://sources.redhat.com/pub/pthreads-win32/.

2) Build the test program:

   gcc -o thread_test.exe \
    -D_REENTRANT \
    -D_THREAD_SAFE \
    -D_POSIX_PTHREAD_SEMANTICS \
    -I../../../src/include/port/win32 \
    thread_test.c \
    -lws2_32 \
    -lpthreadgc2

3) Run thread_test.exe. You should see output like:

    dpage@PC30:/cvs/pgsql/src/tools/thread$ ./thread_test
    Your GetLastError() is thread-safe.
    Your system uses strerror() which is thread-safe.
    getpwuid_r()/getpwuid() are not applicable to Win32 platforms.
    Your system uses gethostbyname which is thread-safe.

    Your platform is thread-safe.