Re: reentrant library functions



On Sep 18, 9:20 pm, David Schwartz <dav...@xxxxxxxxxxxxx> wrote:
On Sep 17, 1:29 pm, Mike <michael.h.william...@xxxxxxxxx> wrote:

On Sep 16, 10:01 pm, David Schwartz <dav...@xxxxxxxxxxxxx> wrote:
Hi, I am trying to create a library of some functions that allow
reentrancy, but I don't want to require compiling with the thread
library, "-lpthread", for programs that use my functions, but that
don't use threads. How do I do that?

Here you say you don't want to require *compiling* with the thread
library.

First, to correct one error in your post, '-lpthread' is a linker flag
and has no effect on compiling. You probably mean '-pthread', which on
many platforms (including Linux), selects compiling and linking for
pthreads support.
I do not quite understand.
My functions use semaphores to ensure that any threaded access
is exclusive (sem_wait() and sem_post()). I need the '-lpthread' flag,
or else I get linker errors.

If you were able to get linker errors, that means you had something to
link. That means that the compiling worked. So you *don't* need to
specify the '-lpthread' flag to compile. If you did, you would never
get linker errors because you'd have nothing to link.

You are using a platform that doesn't require any special compiler
flags to make thread-safe code. However, it's still good practice to
specify '-pthread' just in case. On Linux, this has no effect on
compilation and only affects linking.

I think I understand. I should have asked: For a program that uses
my functions, but not threads, is there a way it can be linked
without
having to state '-lpthread'.

(And, I do define _REENTRANT for compiling my functions.)

-Mike
.



Relevant Pages

  • Re: reentrant library functions
    ... reentrancy, but I don't want to require compiling with the thread ... Does anyone know offhand if the dbm B-tree routines allow threaded ...
    (comp.os.linux.development.system)
  • Re: reentrant library functions
    ... Mike wrote: ... reentrancy, but I don't want to require compiling with the thread ... Depending on what your library does, it may be possible to design the API such that any resources which may be contended (memory buffers, etc.) are passed in as arguments, with no state kept in the library itself. ...
    (comp.os.linux.development.system)
  • Re: reentrant library functions
    ... Here you say you don't want to require *compiling* with the thread ... If you were able to get linker errors, that means you had something to ... specify the '-lpthread' flag to compile. ...
    (comp.os.linux.development.system)
  • Re: reentrant library functions
    ... reentrancy, but I don't want to require compiling with the thread ... First, to correct one error in your post, '-lpthread' is a linker flag ... and has no effect on compiling. ... or else I get linker errors. ...
    (comp.os.linux.development.system)
  • Re: [opensuse] question about compiling an app and installing
    ... for example libpcap-devel or gnome-something-devel. ... compiling to. ... If you know there are particular shared libraries, ... machine rsync (with --delete flag IIRC) ...
    (SuSE)