Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.programming.threads > #223

Re: False sharing

Path csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!goblin1!goblin2!goblin.stu.neva.ru!newsfeed2.atman.pl!newsfeed.atman.pl!.POSTED!not-for-mail
From Edek <edek.pienkowski@gmail.com>
Newsgroups comp.programming.threads
Subject Re: False sharing
Date Wed, 01 Jun 2011 22:09:15 +0200
Organization ATMAN - ATM S.A.
Lines 41
Message-ID <is6697$ge9$1@node2.news.atman.pl> (permalink)
References <c107ab21-41c4-476e-9cb3-71277376f4c1@glegroupsg2000goo.googlegroups.com>
NNTP-Posting-Host 178-37-135-97.adsl.inetia.pl
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Trace node2.news.atman.pl 1306958952 16841 178.37.135.97 (1 Jun 2011 20:09:12 GMT)
X-Complaints-To usenet@atman.pl
NNTP-Posting-Date Wed, 1 Jun 2011 20:09:12 +0000 (UTC)
User-Agent Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.17) Gecko/20110428 Linux/3.1.0-15 Thunderbird/3.1.0
In-Reply-To <c107ab21-41c4-476e-9cb3-71277376f4c1@glegroupsg2000goo.googlegroups.com>
Xref x330-a1.tempe.blueboxinc.net comp.programming.threads:223

Show key headers only | View raw


Summing up: you question was "why does not the buffer change anything"
and "why is it slow".

Why it is slow was the part I was curious in. I think we mostly covered 
the topic.


> The test program's threads update two different memory locations (that's why it it is false sharing, not sharing). Could you please explain why accesses to them should be protected by a mutex?
>
>> The 'volatile' does not guarantee it won't be, this is a common
>> misunderstanding.
>> http://origin-software.intel.com/en-us/blogs/2007/11/30/volatile-almost-useless-for-multi-threaded-programming/
>>
>> DS
>
> I agree that using volatile is usually harmful, however in this experiment I didn't want the compiler
behave optimally. I did verify the assembler of the loop (in one of my 
earlier posts)
and it shows that the memory accesses have not been optimised out from 
the loop.

I don't think volatile is harmful. I think what is harmful is that
people very commonly believe that 'volatile' gives some threading
guarantees. It does not give ANY WHATSOEVER, so it is a false
belief which is a source of plain errors. There are corner cases where
'volatile' is needed in the aspect of threading, I know ONE. [1]

Everything in this thread can be explained by two concepts: AS-IF
rule, and threading guarantees. The rest are technical implementation 
details, which should not be relied on.

HTH
Edek


[1] Specific to gcc, x86 (or was it x86_64?):

  if (try_lock ()) {
      var++;
  }

Back to comp.programming.threads | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

Re: False sharing curious <curious.oskar58@gmail.com> - 2011-06-01 03:25 -0700
  Re: False sharing David Schwartz <davids@webmaster.com> - 2011-06-01 12:51 -0700
  Re: False sharing Edek <edek.pienkowski@gmail.com> - 2011-06-01 22:09 +0200

csiph-web