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: Ian Collins Newsgroups: comp.programming.threads Subject: Re: Is pthread_create( id, 0, f, &something_on_my_stack ); safe? Date: Mon, 21 Nov 2011 20:00:35 +1300 Lines: 32 Message-ID: <9iub8jF7g0U1@mid.individual.net> References: <4EC9C581.405E@2ndquadrant.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net cp/F3ygr/8rCmiNWB6eZfAnLYwR/WgYgovcBzNGht2fWGeWD7p Cancel-Lock: sha1:iYqKcXuBYOgrDh6lcIh7GP2awR4= User-Agent: Mozilla/5.0 (X11; SunOS i86pc; rv:6.0.2) Gecko/20111003 Thunderbird/6.0.2 In-Reply-To: <4EC9C581.405E@2ndquadrant.com> Xref: x330-a1.tempe.blueboxinc.net comp.programming.threads:678 On 11/21/11 04:29 PM, Johann 'Myrkraverk' Oskarsson wrote: > Hi all, > > Given > > void *f( void *j ) > { > int i = *((int *)j); > //.. > } > > void g( void ) > { > pthread_t *id = ...; > int something_on_my_stack = 42; // Life, universe& everything > pthread_create( id, 0, f,&something_on_my_stack ); > > is there any guarantee the value has been copied to f()s stack by the > time pthread_create() returns? No. > Or, to be a little bit more explicit, is there anything I can use for > safe argument passing to newly created threads without allocating new > memory and (presumably) have the threads free it? I can't see any problem with static int something_on_my_stack = 42; -- Ian Collins