It's not clear to me whether this case requires "volatile" in order to work. Can someone please comment?
File1.c has a function called foo(). Inside foo() there is a while loop the depends on a global Boolean. Inside the while loop it calls another function called watchout() that updates the gBool1 variable after some condition has been met. The watchout() function lives in File2.c.
void foo(void) /* This function lives in File1.c */
{
gBool1 = TRUE;
while( gBool1 == TRUE )
{
watchout();
}
}
void watchout(void) /* This function lives in File2.c */
{
static i =0;
if( i < 100 )
{
i++;
}
else
{
gBool1 == FALSE;
i = 0;
}
}
FYI, I did already read this article:
http://processors.wiki.ti.com/index.php/Volatile
Now on the one hand this looks very similar to the semaphore example. Perhaps I'm reading too much into the use of the word "thread" in the description. In the case above there would never be any pre-emption involved, i.e. both functions execute as part of the same thread. Would volatile be required?
Further background... We're dealing with auto-generated code and I believe there may be a bunch of these sorts of things in the code and I'm wondering if we can safely optimize. So in other words, we can't simply add volatile and be done. Every time we regenerate code all the same issues would come back.