From: jp2code on 6 Jun 2007 10:04 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.
From: Scott McPhillips [MVP] on 6 Jun 2007 10:40 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++]
From: Joseph M. Newcomer on 6 Jun 2007 10:57 You need a mutual exclusion mechanism. A mutex and a CRITICAL_SECTION would both work. If you need a timeout, you will have to use a mutex, but if you would be waiting INFINITE, then a CRITICAL_SECTION is a better choice. Also, a mutex would allow you to WaitForMultipleObjects in case you want to implement a shutdown scenario. joe On Wed, 6 Jun 2007 09:04:21 -0500, "jp2code" <poojo.com/mail> 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. > Joseph M. Newcomer [MVP] email: newcomer(a)flounder.com Web: http://www.flounder.com MVP Tips: http://www.flounder.com/mvp_tips.htm
First
|
Prev
|
Pages: 1 2 Prev: CTreeCtrl::SelectItem() behaves weird on VISTA Next: VS2005/Vista issues |