Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-18-2007, 12:09 PM
Member
 
Join Date: Mar 2007
Posts: 41
peiceonly is on a distinguished road
Keyword : volatile
What is this used for ?
Why this is not used for local variables
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 04-18-2007, 12:17 PM
Senior Member
 
Join Date: Mar 2007
Posts: 136
goldhouse is on a distinguished road
The volatile keyword is used on variables that may be modified simultaneously by other threads. This warns the compiler to fetch them fresh each time, rather than caching them in registers. This also inhibits certain optimisations that assume no other thread will change the values unexpectedly. Since other threads cannot see local variables, there is never any need to mark local variables volatile.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 08-09-2007, 01:57 PM
Senior Member
 
Join Date: Jul 2007
Posts: 130
cruxblack will become famous soon enough
I haven't quite get the matter, could u give some examples bout the subject goldhouse?
Or maybe a link about it, kinda hard to understand it sometimes without an example

Thanks
CruxBlack
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 08-09-2007, 03:45 PM
Member
 
Join Date: Aug 2007
Posts: 2
jdev is on a distinguished road
goldhouse example is a good one. I'll give you a different example.

Volatile comes from the C language (not sure C was the first to use it, though!). If you have a hardware register which represents a temperature value, for example, if you don't tell the compiler that that address is volatile the compiler might use an internal register to store that value, which would be wrong because the value keeps changing (in the external device) while the value in internal register won't change. In this case volatile means "get always the value from this address".
Hope this helps
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 08-09-2007, 07:21 PM
Senior Member
 
Join Date: Mar 2007
Posts: 136
goldhouse is on a distinguished road
thanks jdev
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 08-10-2007, 03:26 AM
Senior Member
 
Join Date: Jul 2007
Posts: 130
cruxblack will become famous soon enough
Err...i havent dig too much into threading and concurrency actually, have been reading about it from some books, but i still haven't understand much of its concept
All i can think when u say
Quote:
Originally Posted by jdev
"get always the value from this address"
was, doesn't the static keyword do the same thing? Though, i realize that may not be the case
Ill start a thread in the New to Java section since my questions are gonna be rather basic bout threading and unfit in the Advanced Java, but thanks all

CruxBlack
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 08-10-2007, 10:26 AM
Member
 
Join Date: Aug 2007
Posts: 2
vibhor.ec is on a distinguished road
u cant' serialize volatile variables.i.e. cant save the volatile varible of an object
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
volatile and synchornized goldhouse Threads and Synchronization 3 04-23-2008 09:38 PM
finalize keyword bugger New To Java 1 12-21-2007 10:47 AM
transient keyword Java Tip Java Tips 0 12-11-2007 11:27 AM
volatile variable Java Tip Java Tips 0 12-11-2007 11:26 AM
Use of this keyword Java Tip Java Tips 0 11-18-2007 08:32 PM


All times are GMT +3. The time now is 06:23 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org