Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: Alexander Terekhov Newsgroups: comp.programming.threads Subject: Re: Interlocked operations, volatile Date: Wed, 13 Jul 2011 20:03:01 +0200 Organization: A noiseless patient Spider Lines: 42 Message-ID: <4E1DDDD5.AA6B4306@web.de> References: <99a57186-cf9f-47ee-8955-07df1ce2b126@b21g2000yqc.googlegroups.com> Reply-To: terekhov@web.de Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Injection-Info: mx04.eternal-september.org; posting-host="MCbSEzW5qwGLFMNXJh39IQ"; logging-data="15858"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19ETkYvI0c4JV1YHqbshuDcoWGHzHN2tOc=" X-Mailer: Mozilla 4.77 [en] (Windows NT 5.0; U) X-Accept-Language: en Cancel-Lock: sha1:eJmT3OA/TnkY60mOBclA7Gh22RU= Xref: x330-a1.tempe.blueboxinc.net comp.programming.threads:424 Andrew Che wrote: > > Greetings! > > Q1: Is it true that the only goal of using interlocked operations is > to guarantee that read/write operations are completed in proper order? Not true. > Q2: Is it true that the goal of 'volatile' is the same? Not true. > Q3: Is it nessesary to use 'int* volatile ptr' or some interlocked > operation in line [???] to be sure function2 is correct (see sample > below)? Not necessary. > > == START SAMPLE == > > int value = 42; > int* ptr = 0; > > void function1 () { // called from many threads > cas(&ptr, &value, 0); // some compare-and-swap function > } > > void function2 () { // called from many threads > if(!ptr) { // [???] > return; > some_func(ptr); > } > == END SAMPLE == > > Cheers, > Andrew regards, alexander.