Questions about shared libraries (.so)

Discussion in 'C Programming' started by Paulo da Silva, Feb 7, 2005.

  1. Hi.

    I am writing a shared library to override some libc
    functions.

    I have the following questions:

    Ex.
    int XXX=0;
    void f() {++XXX; ...; --XXX;}

    1.
    Are global data (extern) shared among processes
    or threads? If a process or a thread accesses f while
    another one is also executing f it sees XXX as 0 or 1?

    2.
    Is there any problem not freeing malloc allocated areas in f
    relying on the automatic free at the end of the job?
    I am asking this because I want to share some information
    between sucessive calls to f in a process but I don't know what
    is the last call. So, I don't know when to free the malloc'ed
    areas.

    Any links to literature about these is welcome.

    Thanks for any help.
    Paulo da Silva, Feb 7, 2005
    #1
    1. Advertising

  2. Paulo da Silva wrote:
    > Hi.
    >
    > I am writing a shared library to override some libc
    > functions.
    >
    > I have the following questions:

    [snip]

    > Any links to literature about these is welcome.
    >
    > Thanks for any help.


    Wrong newsgroup. This newsgroup, news:comp.lang.c,
    discusses the _standard_ C language which has no
    facilities for shared libraries. These are outside
    the scope of the language.

    Not all platforms support shared libraries. Please
    consult a newsgroup dedicated to your platform.
    Many newsgroups are listed in the FAQs below.

    --
    Thomas Matthews

    C++ newsgroup welcome message:
    http://www.slack.net/~shiva/welcome.txt
    C++ Faq: http://www.parashift.com/c -faq-lite
    C Faq: http://www.eskimo.com/~scs/c-faq/top.html
    alt.comp.lang.learn.c-c++ faq:
    http://www.comeaucomputing.com/learn/faq/
    Other sites:
    http://www.josuttis.com -- C++ STL Library book
    http://www.sgi.com/tech/stl -- Standard Template Library
    Thomas Matthews, Feb 7, 2005
    #2
    1. Advertising

  3. On Mon, 07 Feb 2005 16:41:55 +0000, Paulo da Silva wrote:

    > Hi.
    >
    > I am writing a shared library to override some libc
    > functions.
    >
    > I have the following questions:
    >
    > Ex.
    > int XXX=0;
    > void f() {++XXX; ...; --XXX;}
    >
    > 1.
    > Are global data (extern) shared among processes
    > or threads?


    That would depend on the implementation and how it implements processes
    and thread which are not C concepts. Typically however threads share the
    same address space whereas processes for normal operations don't.

    Given your reference ot .so lubraries comp.unix.prorgammer might be a
    better place to discuss this.

    > If a process or a thread accesses f while
    > another one is also executing f it sees XXX as 0 or 1?


    That would depend on when XXX is accessed. Also consider makin XXX
    volatile.

    > 2.
    > Is there any problem not freeing malloc allocated areas in f relying on
    > the automatic free at the end of the job?


    That depends on what you mean by a "job". You should free memory when you
    no longer need it or else you might have a memory leak. On reasonable
    systems the memory allocated by a program is reclaimed when the program
    terminates.

    > I am asking this because I
    > want to share some information between sucessive calls to f in a process
    > but I don't know what is the last call. So, I don't know when to free
    > the malloc'ed areas.


    If it is a single allocation that's not too large that may not be a
    problem, you might think of it like a static variable.

    Lawrence
    Lawrence Kirby, Feb 7, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tascien

    Shared libraries on dotnet

    Tascien, Jul 23, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    364
    Ken Cox [Microsoft MVP]
    Jul 24, 2004
  2. Dave Neary

    JVM and shared libraries

    Dave Neary, Jun 9, 2004, in forum: Java
    Replies:
    13
    Views:
    1,193
  3. Replies:
    0
    Views:
    340
  4. Karsten Wutzke
    Replies:
    21
    Views:
    914
    Roedy Green
    Jun 29, 2007
  5. Sriram Srinivasan
    Replies:
    13
    Views:
    561
    Benjamin Kaplan
    Nov 12, 2009
Loading...

Share This Page