Click here to Skip to main content
16,004,479 members
Home / Discussions / C#
   

C#

 
GeneralVolatile?? :confused: Pin
geekfromindia11-Feb-08 13:38
geekfromindia11-Feb-08 13:38 
GeneralRe: Volatile?? :confused: Pin
Colin Angus Mackay11-Feb-08 13:52
Colin Angus Mackay11-Feb-08 13:52 
GeneralRe: Volatile?? :confused: Pin
geekfromindia11-Feb-08 14:33
geekfromindia11-Feb-08 14:33 
GeneralRe: Volatile?? :confused: Pin
MidwestLimey11-Feb-08 14:35
professionalMidwestLimey11-Feb-08 14:35 
GeneralRe: Volatile?? :confused: Pin
geekfromindia11-Feb-08 14:39
geekfromindia11-Feb-08 14:39 
GeneralRe: Volatile?? :confused: Pin
MidwestLimey12-Feb-08 4:26
professionalMidwestLimey12-Feb-08 4:26 
GeneralRe: Volatile?? :confused: Pin
MarkB77711-Feb-08 16:30
MarkB77711-Feb-08 16:30 
GeneralRe: Volatile?? :confused: Pin
geekfromindia11-Feb-08 17:09
geekfromindia11-Feb-08 17:09 
MarkBrock wrote:
As long as the world turns there will always be geeks - computer/software engineering will only move forward. .


Right said Mark...

Colin Angus Mackay wrote:
If you update the variable in the processor cache and another thread requests it from memory the the value will be wrong.


My Ques: (rephrasing it a bit) - If we say that a thread1 reads a variable from memory and that is stored in CPU cache for optimization. now thread1 accesses that variable from cache all the time...why doesn't other threads access that variable from cache instead of going to memory.

So it seems that here optimization is being done by thread1 so it cannot be accessed from thread2 which will always access variable again from memory causing all the problem.

here's an example on volatile for more details:

int i = 0;

loop(i=0 to i=100)
{
//do something
}

here if compiler optimizes the variable before loop, it will have value 0 in memory and loop will only update value in cache.
Now if any other method tried accessing this variable inbetween this loop it will get an outdated value.
Declaring variable i as volatile tells compiler to not to optimize it in cache.

Keep DotNetting!!

GeekFromIndia

GeneralRe: Volatile?? :confused: Pin
Guffa11-Feb-08 22:59
Guffa11-Feb-08 22:59 
GeneralRe: Volatile?? :confused: Pin
Daniel Grunwald12-Feb-08 0:25
Daniel Grunwald12-Feb-08 0:25 
Generalvoice chatting over lan or simpy between two pcs Pin
rao raja11-Feb-08 11:49
rao raja11-Feb-08 11:49 
GeneralRe: voice chatting over lan or simpy between two pcs Pin
led mike11-Feb-08 11:59
led mike11-Feb-08 11:59 
GeneralRe: voice chatting over lan or simpy between two pcs Pin
User 665811-Feb-08 11:59
User 665811-Feb-08 11:59 
GeneralProblem with DialogResult Pin
shea85111-Feb-08 11:10
shea85111-Feb-08 11:10 
GeneralRe: Problem with DialogResult Pin
shea85111-Feb-08 11:32
shea85111-Feb-08 11:32 
GeneralRe: Problem with DialogResult Pin
DaveyM6911-Feb-08 11:51
professionalDaveyM6911-Feb-08 11:51 
GeneralRe: Problem with DialogResult Pin
shea85111-Feb-08 12:18
shea85111-Feb-08 12:18 
GeneralMy project is not reflecting current changes Pin
R.A.C11-Feb-08 9:45
R.A.C11-Feb-08 9:45 
GeneralRe: My project is not reflecting current changes Pin
Pete O'Hanlon11-Feb-08 10:06
mvePete O'Hanlon11-Feb-08 10:06 
GeneralRe: My project is not reflecting current changes Pin
Luc Pattyn11-Feb-08 10:38
sitebuilderLuc Pattyn11-Feb-08 10:38 
QuestionUDP Send function sends duplicate data Pin
Chase Davis11-Feb-08 9:34
Chase Davis11-Feb-08 9:34 
GeneralRe: UDP Send function sends duplicate data Pin
led mike11-Feb-08 10:01
led mike11-Feb-08 10:01 
GeneralRe: UDP Send function sends duplicate data Pin
Chase Davis11-Feb-08 11:09
Chase Davis11-Feb-08 11:09 
GeneralRe: UDP Send function sends duplicate data Pin
led mike11-Feb-08 11:16
led mike11-Feb-08 11:16 
GeneralRe: UDP Send function sends duplicate data Pin
Chase Davis11-Feb-08 12:30
Chase Davis11-Feb-08 12:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.