Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.os.linux.development.apps > #428
| From | Rainer Weikusat <rweikusat@mssgmbh.com> |
|---|---|
| Newsgroups | comp.os.linux.development.apps |
| Subject | Re: object file memory |
| Date | 2012-02-09 19:00 +0000 |
| Message-ID | <87zkcral2h.fsf@sapphire.mobileactivedefense.com> (permalink) |
| References | (2 earlier) <jgrc5t$5f0$1@dont-email.me> <jgrmj8$6pc$1@dont-email.me> <alpine.DEB.2.00.1202072202080.25401@login01.caesar.elte.hu> <jgs7dk$ng5$1@dont-email.me> <jgvbqo$uin$1@dont-email.me> |
Bill M <wpmccormick@just_about_everywhere.com> writes:
[...]
> So I've re-written my client application to something I think is more
> manageable, but I'm still having some trouble. It seems that global
> variables declared with __thread are not keeping their values. I have
> something that looks like this:
>
> *** client.c ***
> static __thread COMM_STATE comm_state;
> static __thread int sockfd;
> static __thread struct sockaddr_in their_addr;
>
> static int connect(SERVER server)
> {
> if(comm_state == CONNECTED) return ALREADY_CONNECTED;
> ...
> sockfd = socket( ... );
> ...
> connect(sockfd, ...
>
> }
>
> int client_write(SERVER server, char* buffer)
> {
> for(;;) {
> if((connect(server)) != ALREADY_CONNECTED)
> continue;
>
> if((comm_send(buffer)) != SUCCESS)
> continue;
>
> //now get a reply here
> ...
> }
> }
>
> *** client_app.c ***
> extern int client_write(SERVER server, char* buffer) ;
>
> So I think you get the idea, and my question is this:
>
> Should globals in client.c be persistent from one client_write call to
> the next for each thread in client_app.c that calls client_write?
Yes. Otherwise, there would be little point in having thread-local
variables. I've used them myself quite a couple of times without
problems.
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