Should I use "Volatile" in the following case?
Please note that my application has several .c source files.
Module1.c
static char status_variable = 0;
Modify1()
{
status_variable = 'a';
}
Modify2()
{
status_variable = 'x';
}
char GetStatus()
{
return status_variable;
}
Function Modify
can be called from other .c files based on events (not via ISR)
Module2.C
TakeAction()
{
if(GetStatus() == 'a')
{
//do something
}
else
{
//do something
}
}
Now my question is, do I need to declare status_variable
like volatile
in this case?
EDIT1:
My application is a 16-bit microcontroller (RL78), I am not using any operating system.
EDIT2:
As some are commenting, multithreading was not in my mind. I have written down a simple uncaught circular motion scheduler for my application. I have no idea about multi-threaded environment and what makes the variable volatile in this case. How is it different from my environment? If someone can develop it, it will be of great help.
source to share