Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!nuzba.szn.dk!pnx.dk!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Rainer Weikusat Newsgroups: comp.os.linux.development.apps Subject: Re: object file memory Date: Thu, 09 Feb 2012 19:00:38 +0000 Lines: 50 Message-ID: <87zkcral2h.fsf@sapphire.mobileactivedefense.com> References: <20120207000059.76@kylheku.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: individual.net zh1/oabKpI6SLFaEMzM5tA/fbsDS1UOBGRx8PZTNd0+fAk/vw= Cancel-Lock: sha1:/JEI1N/yD7JY1Od9H7f7RYY6Ybc= sha1:4gzmhT9FzIFq6/ZEtJVSdoxa11s= User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.2 (gnu/linux) Xref: x330-a1.tempe.blueboxinc.net comp.os.linux.development.apps:428 Bill M 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.