🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #8608

Re: volatile keyword - doesn't seem to make a change

#8608
From: Dave Bird
Date: Sun, 11 Mar 2001 16:38
35 lines
2577 bytes
In article <3aab9aa2_2@dnews>, Torsten Welches <torsten.welches@who.care
s.netcologne.de> writes
>Yonatan,
>
>no, non-volatile does not mean that one thread *never* sees the
>non-synchronized changes to the variable.
>Rather volatile ensures that a change by another thread is noticed
>"immediately" while it is unspecified *when* (not *if*) this will happen for
>a non-volatile variable. This entirely depends on the JVM implementation
>then.

 This is also the case in C++.  Volatile says that the contents of
 the variable can change AT ANY MOMENT independent of the currently
 running code (for example, you might have mapped an I/O device into
 the memory range rather than using ports).  In which case it must
 be loaded from its memory location EACH TIME you read its value.
 Otherwise the compiler might, if you read the value 2 or 3 times, 
 speed the code up by keeping it in a hardware register so it need
 not be read from memory again "because it will not have changed".

 If you failed to mark a changeable location as "volatile" it 
 would simply find the change... some unspecified time later
 when it read a fresh copy from the memory location.


 If you really want the value of a variable unchanged just as it 
 was when the thread started, then you must make a local copy of
 the variable when the thread starts and use that instead, like

 protected int memLocInitially = Main.memLoc;


-- 
   ^-^-^-@@-^-;-^   http://www.xemu.demon.co.uk/
        (..)__u     news:alt.smoking.mooses
Technical Details
Message-ID: <D9jCapAHo6q6Ewiv@xemu.demon.co.uk>
Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-03!supernews.com!news-out.usenetserver.com!news-out-sjo.usenetserver.com!feed2.onemain.com!feed1.onemain.com!feeder.qis.net!dispose.news.demon.net!news.demon.co.uk!demon!xemu.demon.co.uk!dave
References: <3aaa9320_2@dnews> <3aab9aa2_2@dnews>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,c0d5023d960f16ab
X-Google-Attributes: gidf74b3,public
X-Google-ArrivalTime: 2001-03-11 13:30:07 PST
Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-03!supernews.com!news-out.usenetserver.com!news-out-sjo.usenetserver.com!feed2.onemain.com!feed1.onemain.com!feeder.qis.net!dispose.news.demon.net!news.demon.co.uk!demon!xemu.demon.co.uk!dave
From: Dave Bird <dave@xemu.demon.co.uk>
Newsgroups: borland.public.jbuilder.java.language
Subject: Re: volatile keyword - doesn't seem to make a change
Date: Sun, 11 Mar 2001 16:38:31 +0000
Organization: none
Message-ID: <D9jCapAHo6q6Ewiv@xemu.demon.co.uk>
References: <3aaa9320_2@dnews> <3aab9aa2_2@dnews>
NNTP-Posting-Host: xemu.demon.co.uk
X-NNTP-Posting-Host: xemu.demon.co.uk:158.152.196.209
X-Trace: news.demon.co.uk 984346118 nnrp-14:28883 NO-IDENT xemu.demon.co.uk:158.152.196.209
X-Complaints-To: abuse@demon.net
MIME-Version: 1.0
X-Newsreader: Turnpike Integrated Version 5.00 U <dQumtnY$x4rJ2u5tL5fS$n2vuP>
Lines: 35