Thread safe malloc in Tru64?

From: Ioannis E. Venetis (iev_at_hpclab.ceid.upatras.gr)
Date: 11/20/03


Date: Thu, 20 Nov 2003 16:11:01 +0200

Hello,

I am trying to create a library that will run, among other architectures, on
Tru64/Alpha systems.
Of course, this library has a machine independant (the same for all
architectures) and a machine
dependant part. For some reasons, I chose to use the
thread_create/thread_get_state/
thread_set_state/thread_resume/thread_terminate interface in the machine
dependant part of the
library to manage kernel-level threads on Tru64 Unix systems. I am
mentioning it in case this has
something to do with the problem I will describe.

Now, the problem is that all my applications that use this library crash on
Tru64 Unix systems
(but not on other systems the library compiles on). After spending hours on
debugging and
inserting printf's on several places I found what was going wrong. The
malloc() function, when
called by all threads of the application, returns most of the time the same
starting address of the
allocated memory for different threads. This seems to be an issue with
thread-safety of the
malloc() function. I searched the Internet and found that I had to link my
applications with a few
libraries, in order to make them thread-safe. Some of the possibilities I
found are:

-lpthreads -lmach -lc_r
-lpthread -lmach -lexc -lc

I also tried other combinations
(-lpthread -lmach -lc_r, -lpthread -lmach -lc, -lpthreads -lmach -lc,...)
but none of them solved the problem. I also tried to use -D_REENTRANT and/or
-D_THREAD_SAFE when compiling the library and the applications, but the
problem still remains.

Finally, I replaced malloc() with mmap(), and the applications run perfectly
in this case, so I doubt
that something else is wrong in the library.

I would appreciate it if someone could give me some directions on how to
link my libray and applications
with thread-safe versions of all necessary libraries, both for shared and
static versions.

Some system specific information:

OS: Compaq Tru64 UNIX V5.1 (Rev. 732)
Compiler: gcc -v
Reading specs from /usr/local/lib/gcc-lib/alphaev6-dec-osf4.0e/2.95.2/specs
gcc version 2.95.2 19991024 (release)

Thank you in advance,

Ioannis E. Venetis
PhD Student - Research Assistant
High Performance Information Systems Laboratory
Computer Engineering and Informatics Department
University of Patras, Greece
URL: http://www.hpclab.ceid.upatras.gr/pgroup/members/iev



Relevant Pages

  • Re: Can MS listen to customers?
    ... IE is comprised of a set of libraries that other applications use. ... a HUGE portion of even a minimal install of Windows (or even in ... For Windows, Notepad, Paint, IE, OE, msconfig, Wordpad, Hearts, NT ...
    (microsoft.public.windowsxp.general)
  • [Full-Disclosure] Overflow in SunRPC-derived XDR libraries
    ... Applications using vulnerable implementations of SunRPC-derived XDR ... BSD-derived libraries with XDR/RPC routines ... Note that this vulnerability is similar to, but distinct from, ... Because SunRPC-derived XDR libraries are used by a variety of vendors ...
    (Full-Disclosure)
  • Re: Reading great code
    ... not aware of any mission-critical applications that use .NET, ... and libraries) or no operating system at all (except perhaps ... The C language, for example, can't be used ... more than Java is a prototyping platform. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Reading great code
    ... aware of any mission-critical applications that use .NET, and the more critical applications use specialist operating systems (and compilers, and libraries) or no operating system at all, for just the reason you've spotted. ... And even when the languages used do have code libraries available, those libraries are generally not used unless they have been specifically designed with mission-critical applications in mind. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: [Lit.] Buffer overruns
    ... >>safe application difficult and secure applications impossible. ... >>libraries can be shrunk to fit and C's RTL is one of those. ... applications it might be (I suspect the performance-sensitive apps are ...
    (sci.crypt)