Re: Question about Threading
Re: Question about Threading
- Subject: Re: Question about Threading
- From: Erik Buck <email@hidden>
- Date: Mon, 8 Aug 2005 19:54:50 -0400
The volatile key word informs the C compiler that every reference to
a variable should be made from memory and not from a previously
fetched value that happens to still be in a register.
In other words, the contents of the variable are volatile (changing)...
The volatile key word removes the following assumption from the
compiler's code generator/optimizer:
If the code being generated does not modify a variable in a
particular interval then the variable is not modified in that interval.
Stated the opposite way, the variable's value may change at any time
even if the code that is generated does not change the variable.
Example
// This code is an infinite loop
int foobar = 1;
while(foobar)
{
printf("in loop\n");
}
// This code is not necessarily an infinite loop because
// the value of foobar could change at any time. Perhaps
// another thread modifies it or a signal, or an interrupt
// or another process using shared memory etc.
volatile int foobar = 1;
while(foobar)
{
printf("in loop\n");
}
Don't even consider writing multi-threaded code with a C derived
language before understanding and internalizing the use of the
volatile key word.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden