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


Groups > comp.programming.threads > #1800

Re: forcing the compiler to reload from memory with c++0x

Path csiph.com!eeepc.pasdenom.info!news.pasdenom.info!news.dougwise.org!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!weretis.net!feeder4.news.weretis.net!news1.tnib.de!feed.news.tnib.de!news.tnib.de!feed.cnntp.org!news.cnntp.org!not-for-mail
From Anthony Williams <anthony.ajw@gmail.com>
Newsgroups comp.programming.threads
Subject Re: forcing the compiler to reload from memory with c++0x
References <4d3cee42$0$1209$426a74cc@news.free.fr> <1d21ad0a-db55-460e-aeb6-66f6d19369ea@i13g2000yqe.googlegroups.com> <4d3e2e3f$0$21517$426a34cc@news.free.fr> <4D40A4C7.16E6F9AE@web.de> <69d82db7-34be-4de7-86c4-2f39cc1e6df3@m13g2000yqb.googlegroups.com> <4d4221e9$0$17247$426a74cc@news.free.fr> <947b33d5-2509-4f0c-9256-a7c3de35578e@24g2000yqa.googlegroups.com> <87mxmlxxry.fsf@justsoftwaresolutions.co.uk> <ihv8t6$bmr$1@news.eternal-september.org> <87oc6yxdcw.fsf@justsoftwaresolutions.co.uk> <ii745u$5q3$1@news.eternal-september.org> <87sjw8w4b5.fsf@justsoftwaresolutions.co.uk> <iietha$f3a$1@news.eternal-september.org> <iifb30$9d3$1@news.eternal-september.org> <99c58954-6434-4135-b90a-da60dc1d865d@i14g2000prm.googlegroups.com> <iifuoj$1j3$1@news.eternal-september.org> <d1258777-65bc-4ea1-8494-70e8a6d00d98@y35g2000prc.googlegroups.com> <92f9e621-9df2-4ce4-bfa5-64f29924112b@z3g2000prz.googlegroups.com>
Date Fri, 04 Feb 2011 09:21:52 +0000
Message-ID <87fws49mtr.fsf@justsoftwaresolutions.co.uk> (permalink)
User-Agent Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux)
Cancel-Lock sha1:28R45ofkfgNshRX9bbATwk9cPmc=
MIME-Version 1.0
Content-Type text/plain; charset=us-ascii
Lines 50
Organization CNNTP
NNTP-Posting-Host 8dce39c0.read.cnntp.org
X-Trace DXC=5:RU4f>cB0I8jWYT8D?UN@WoT\PAgXa?Af8aof<bcn:B31?8ZVJ3gMEGj6PdB418WNEIXj<D98h=KSm3?Z4QHZ8C
X-Complaints-To abuse@cnntp.org
Xref csiph.com comp.programming.threads:1800

Show key headers only | View raw


Joshua Maurice <joshuamaurice@gmail.com> writes:

> Well, specifically, the compiler may optimize this:
>   atomic<int> a_int;
>   //...
>   int tmp = a_int.get(relaxed);
>   do_something(tmp);
>   for ( ; ! a_int.get(relaxed) ; )
>   {
>   }
>
> to this:
>   atomic<int> a_int;
>   //...
>   int tmp = a_int.get(relaxed);
>   do_something(tmp);
>   for ( ; ! tmp ; tmp = a_int.get(relaxed))
>   {
>   }

Correct (assuming that do_something doesn't introduce any memory
ordering constraints). Then, if it can prove that !tmp is false
(i.e. tmp is non-zero) then the loop will never execute, so it can omit
the whole loop.

> But it cannot optimize it to this:
>   atomic<int> a_int;
>   //...
>   int tmp = a_int.get(relaxed);
>   do_something(tmp);
>   for ( ; ! tmp ; )
>   {
>   }

Correct.

> It's perfectly fine to remove a finite number of loads (assuming it
> doesn't violate other visibility requirements) as the first rewrite
> does, but it cannot remove /all/ loads from a loop like the second
> rewrite, because that would violate the "become visible in a
> 'reasonable' [read: finite] amount of time" guarantee.

Correct.

Anthony
-- 
Author of C++ Concurrency in Action     http://www.stdthread.co.uk/book/
just::thread C++0x thread library             http://www.stdthread.co.uk
Just Software Solutions Ltd       http://www.justsoftwaresolutions.co.uk
15 Carrallack Mews, St Just, Cornwall, TR19 7UL, UK. Company No. 5478976

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


Thread

Re: forcing the compiler to reload from memory with c++0x Andy Venikov <swojchelowek@gmail.com> - 2011-02-03 23:19 -0500
  Re: forcing the compiler to reload from memory with c++0x Andy Venikov <swojchelowek@gmail.com> - 2011-02-06 23:17 -0500
  Re: forcing the compiler to reload from memory with c++0x Anthony Williams <anthony.ajw@gmail.com> - 2011-02-04 09:21 +0000
  Re: forcing the compiler to reload from memory with c++0x Anthony Williams <anthony.ajw@gmail.com> - 2011-02-04 08:42 +0000
  Re: forcing the compiler to reload from memory with c++0x Joshua Maurice <joshuamaurice@gmail.com> - 2011-02-03 22:45 -0800
    Re: forcing the compiler to reload from memory with c++0x Joshua Maurice <joshuamaurice@gmail.com> - 2011-02-04 00:28 -0800

csiph-web