Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.os.linux.development.apps > #419
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Bill M <wpmccormick@just_about_everywhere.com> |
| Newsgroups | comp.os.linux.development.apps |
| Subject | Re: object file memory |
| Date | Tue, 07 Feb 2012 08:40:44 -0600 |
| Organization | A noiseless patient Spider |
| Lines | 63 |
| Message-ID | <jgrd5h$b2n$1@dont-email.me> (permalink) |
| References | <jgpkvf$c83$1@dont-email.me> <20120207000059.76@kylheku.com> <jgrc5t$5f0$1@dont-email.me> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| Injection-Date | Tue, 7 Feb 2012 14:40:49 +0000 (UTC) |
| Injection-Info | mx04.eternal-september.org; posting-host="ep43mLzI/jofXxL2elOFPA"; logging-data="11351"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+yYp3N5DvAX8rpROp9eZ2Y1zd528IUs4A=" |
| User-Agent | Mozilla/5.0 (Windows NT 6.1; WOW64; rv:9.0) Gecko/20111222 Thunderbird/9.0.1 |
| In-Reply-To | <jgrc5t$5f0$1@dont-email.me> |
| Cancel-Lock | sha1:m+bjJhJkLDkEdgvOiBTjz2OMDak= |
| Xref | x330-a1.tempe.blueboxinc.net comp.os.linux.development.apps:419 |
Show key headers only | View raw
Bill M wrote, On 2/7/2012 8:23 AM:
> Kaz Kylheku wrote, On 2/6/2012 5:07 PM:
>> On 2012-02-06, Bill M<wpmccormick@just_about_everywhere.com> 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.
>
Perhaps I cannot mix thread local GCC extensions with p_thread's. I see
the following errors:
root@fiberio:/home/fiber/src/plccommd# make
gcc -g -Wall -pthread -lrt -I.. -I../../include -c -o ocxclient.o
ocxclient.c
ocxclient.c: In function 'comm_connect':
ocxclient.c:78: error: cannot convert to a pointer type
ocxclient.c: In function 'start_client':
ocxclient.c:91: warning: passing argument 1 of 'pthread_create' makes
pointer from integer without a cast
/usr/include/pthread.h:227: note: expected 'pthread_t * __restrict__'
but argument is of type 'pthread_t'
line 78:
if(connect(sockfd, (struct sockaddr *)their_addr, sizeof(struct
sockaddr)) == -1) {
line 91:
if ( pthread_create(client, NULL, ocx_client, server) != 0 ) {
Back to comp.os.linux.development.apps | Previous | Next — Previous in thread | Next in thread | Find similar
object file memory Bill M <wpmccormick@just_about_everywhere.com> - 2012-02-06 16:41 -0600
Re: object file memory Kaz Kylheku <kaz@kylheku.com> - 2012-02-06 23:07 +0000
Re: object file memory Bill M <wpmccormick@just_about_everywhere.com> - 2012-02-07 08:23 -0600
Re: object file memory Bill M <wpmccormick@just_about_everywhere.com> - 2012-02-07 08:40 -0600
Re: object file memory Bill M <wpmccormick@just_about_everywhere.com> - 2012-02-07 08:58 -0600
Re: object file memory Bill M <wpmccormick@just_about_everywhere.com> - 2012-02-07 11:21 -0600
Re: object file memory "Ersek, Laszlo" <lacos@caesar.elte.hu> - 2012-02-07 22:09 +0100
Re: object file memory Bill M <wpmccormick@just_about_everywhere.com> - 2012-02-07 16:08 -0600
Re: object file memory Bill M <wpmccormick@just_about_everywhere.com> - 2012-02-08 20:42 -0600
Re: object file memory Rainer Weikusat <rweikusat@mssgmbh.com> - 2012-02-09 19:00 +0000
Re: object file memory Joe Beanfish <joe@nospam.duh> - 2012-02-09 11:15 -0500
csiph-web