I'm working pre C++11 otherwise I'd just use include thread and atomic variables to fulfill my needs, however, can't do that. Got a class that when instanced starts several threads. Within a thread launched function I've got something like:
void ThisClass::ThisThread()
{
while (runThisThread)
{
// doing stuff
}
}
And another function that would be:
void ThisClass::StopThisThread()
{
runThisThread = false; // 'runThisThread' variable is 'volatile bool'
}
A thread will be chewing through a buffer based on indexes assigned from another thread. So one thread would assign a value that another thread would never do anything but read that value. My plan was to use more volatile memory to assign those index values. However, this question suggests I'm using volatile memory incorrectly When to use volatile with multi threading?. What is the correct way pre-C++11 to handle memory in a multithreaded class like this? Keep in mind I am not allowing more than one thread to assign a single variable while each thread may read that variable.
EDIT: Forgot to include that this is a Windows program with no need for cross platforming. I'm using afxwin.h AfxBeginThread() for my threading.