Re: Loop for AfxBeginThread
jp2code wrote:
Ok. Between the two replies, it is obvious that setting a BOOL value is the
wrong way to go.
There is only the main thread and the worker thread (2 threads).
Now the question becomes:
* Should I use a mutex or something else?
I'm leaning towards a mutex after reading many of Joseph Newcomer's essays,
but it is a lot of information on those essays, and I may have missed the
big picture.
You should use a CRITICAL_SECTION. Between threads of the same process
it provides the same functionality as a mutex but is a lot more
efficient. A mutex is required when synchronizing multiple programs, a
critical section when synchronizing multiple threads within the same
program.
You initialize the critical section, then each thread does the following:
EnterCriticalSection(&cs);
....access the shared resource
LeaveCriticalSection(&cs);
While thread A is between the calls, thread B is suspended if it calls
EnterCriticalSection. When A leaves, B resumes.
--
Scott McPhillips [MVP VC++]