Re: WaitForSingleObject() failing?



On Fri, 06 Jan 2006 16:08:17 -0500, Joseph M. Newcomer
<newcomer@xxxxxxxxxxxx> wrote:

>Yes. The issue is whether you use a synchronous join or an asynchronous join. I have
>tended more and more in recent years to using an asynchronous join because I don't get
>caught even inadvertently in a situation where there can be a thread deadlock.
>
>In one case, I had some variable number of threads, n, in the program. All I did was keep
>a reference count of outstanding threads, and when OnClose happened, I deferred executing
>the parent class OnClose until the reference count of outstanding threads had gone to
>zero. So all OnClose did was simply initiate thread shutdown and return; the "join" was
>when the outstanding thread count went to zero.

Unless you WaitForSingleObject (or use one of its cousins), you still have
a race condition. Finding a reference count equal to zero is not a
substitute for finding a thread handle signaled.

--
Doug Harrison
Visual C++ MVP
.



Relevant Pages

  • Re: WaitForSingleObject() failing?
    ... Since nothing accesses the thread after that point, ... The issue is whether you use a synchronous join or an asynchronous join. ... >>a reference count of outstanding threads, and when OnClose happened, I deferred executing ...
    (microsoft.public.vc.mfc)
  • Re: WaitForSingleObject() failing?
    ... The issue is whether you use a synchronous join or an asynchronous join. ... a reference count of outstanding threads, and when OnClose happened, I deferred executing ... MVP Tips: http://www.flounder.com/mvp_tips.htm ...
    (microsoft.public.vc.mfc)