When writing C programs that need to split a file's scope variable between the application and the interrupt routine / thread / callback procedure, it is well known that the variable must be declared mutable, otherwise the compiler may make incorrect optimizations. This is an example of what I mean:
int flag;
void some_interrupt (void)
{
flag = 1;
}
int main()
{
flag = 0;
...
x = flag;
}
To prevent the above error, the flag should be declared as mutable.
My question is: how is this applicable to C ++ when creating a class containing a stream?
I have a class that looks something like this:
class My_thread
{
private:
int flag;
static void thread_func (void* some_arg)
{
My_thread* this_ptr= (My_thread*)some_arg;
}
};
"some_arg" will contain a pointer to an instance of the class, so each "My_thread" object has its own thread. Through this pointer, it will access member variables.
, "this_ptr" ? "" ? , -, "" volatile?
, , , .
EDIT: !
..
, , , , , . , C, , ++.