Re: object file memory



Kaz Kylheku wrote, On 2/6/2012 5:07 PM:
On 2012-02-06, Bill M<wpmccormick@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
I have an object file foo.o that I want to link to an executable. The
main executable creates a number of child threads that use code and
variables from foo.o.

Do you have the source code for foo.o that you can tweak and recompile?
Yes

I've included a very simplistic representation at
the end. My question is, how can each child thread (worker) get it's own
private copy of global variables foo_char and foo_int? Or does that just
happen auto-magically?

Why would that happen automagically? It's completely the wrong thing which
would break most programs.

** foo.c **
char foo_char;
int foo_int;

These are static variables, which are understood to be single-instance,
and any correct program relies on them being that way. Automagically making
these thread-local would be broken behavior.

GCC has extensions for declaring statics thread local. Check the GCC
documentation for the setion on "Thread-Local Storage", but the gist of it is:

__thread char foo_char;

There is also an explicit POSIX API for managing thread-specific values
accessed by keys: pthread_key_create, pthread_setspecific, etc.

So I just started reading about keys (after my original post here) and I was hoping for something even easier. The GCC thread local extensions seem pretty simple to implement. I give that a try first.

Thanks!!
.



Relevant Pages

  • Re: object file memory
    ... main executable creates a number of child threads that use code and ... GCC has extensions for declaring statics thread local. ...
    (comp.os.linux.development.apps)
  • Re: object file memory
    ... main executable creates a number of child threads that use code and ... GCC has extensions for declaring statics thread local. ...
    (comp.os.linux.development.apps)
  • Re: object file memory
    ... main executable creates a number of child threads that use code and ... GCC has extensions for declaring statics thread local. ... ocxclient.c:78: error: cannot convert to a pointer type ... if(connect(sockfd, (struct sockaddr *)their_addr, sizeof(struct ...
    (comp.os.linux.development.apps)
  • Re: object file memory
    ... main executable creates a number of child threads that use code and ... Do you have the source code for foo.o that you can tweak and recompile? ... GCC has extensions for declaring statics thread local. ...
    (comp.os.linux.development.apps)