* Re: pthreads on DEC 8400
1996-03-13 5:00 pthreads on DEC 8400 William R. Pearson
@ 1996-03-14 5:00 ` Dave Butenhof
0 siblings, 0 replies; 2+ messages in thread
From: Dave Butenhof @ 1996-03-14 5:00 UTC (permalink / raw)
William R. Pearson wrote:
>
> I have a threaded program that runs fine on a dual processor DEC Alpha
> 2100 4/275 under OSF/1 3.0B. Unfortunately, when I compile, link and
> run the program on an Alpha 8400 under DIGITAL UNIX 3.2C, I get the
> following message:
>
> ================
> > dbx t_compfa
> dbx version 3.11.8
> Type 'help' for help.
>
> main: 102 unsigned char *aa0=NULL, *aa1, *aa1ptr;
>
> (dbx) stop in h_init
> [2] stop in h_init
> (dbx) run mchu.aa protein_test.lib
> signal Segmentation fault at >*[port_allocate, 0x3ff82808f5c] stq r26, 0(sp)
> (dbx)
>
> ================
>
> This happens before anything interesting (or threaded) happens in the program,
> so I assume that I am linking something wrong. Here is the relevant part of
> the Makefile:
>
> ================
> CC= cc -g
> HFLAGS= -o
> THR_LIBS = -lcmalib -lpthreads
>
> $(CC) $(HFLAGS) t_compfa (lots of .o files) -lm $(THR_LIBS)
> ================
>
> Could someone tell me the correct link options and libraries to use for
> a pthread'ed program on a DEC Alpha 8400 using V3.2C?
>
> Bill Pearson
This is a common problem with programs that were incorrectly built on 3.0 and
earlier systems, then moved to 3.2. The initialization protocol between libc
and libpthreads was improved, removing some circular dependencies with which
OSF had left us. However, it wasn't until we saw problems like yours that we
realized how many people had been "successfully" running badly built programs,
and that they were broken by the new initialization protocol.
The correct way to build a threaded program entirely within cc is to simply
replace your cc make rule with
$(CC) $(HFLAGS) t_compfa [...] -lm -lcmalib -threads
This assumes you're actually using "libcmalib", which is nothing but a portable
"atomic queue" package (cma_lib_ function names). If you're not using those,
you can (and should) drop the -lcmalib.
If you're going to link a shared library using ld, unfortuately, you need to
know a little more -- ld doesn't support "-threads". You should still COMPILE
using -threads, however. To link using ld (prior to Digital UNIX 4.0), use
ld [...] -lpthreads -lmach -lc_r -lc
That grouping MUST appear at the end of the list of libraries, IN THAT ORDER!
If you're compiling using gcc or cxx instead of cc, and can't use -threads to
compile, then you need to know the compile-time contribution of -threads, which
is "-D_THREAD_SAFE". This critical little definition provides the thread-safe
version of errno. Without it, errno will not work! (Your code will be trying
to use the global "extern int errno;" while libpthreads, libc_r, and other
thread safe code in the process is using the per-thread errno.)
On Digital UNIX 4.0, this is all the same if you're using the legacy CMA or
1003.4a/D4 pthread interfaces. However, if you want to switch to the standard
1003.1c-1995 pthread interfaces (and you SHOULD), then you need to compile or
link with "-pthread" instead of "-threads". The list of libraries has changed,
too -- "-lpthread -lmach -lexc -lc". (There's no more libc_r, thankfully.)
+--------------------------------------------------------------------------+
| Dave Butenhof Digital Equipment Corporation |
| butenhof@zko.dec.com 110 Spit Brook Rd, ZKO2-3/Q18 |
| Phone: 603.881.2218, FAX: 603.881.0120 Nashua, NH 03062-2711 |
| "Better Living Through Concurrency" |
+--------------------------------------------------------------------------+
^ permalink raw reply [flat|nested] 2+ messages in thread