Re: WaitForSingleObject() failing?



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.
joe

On Fri, 06 Jan 2006 12:12:49 -0600, "Doug Harrison [MVP]" <dsh@xxxxxxxx> wrote:

>On Fri, 06 Jan 2006 10:39:11 -0500, Joseph M. Newcomer
><newcomer@xxxxxxxxxxxx> wrote:
>
>>Not really. I have eliminated any need to wait for threads by handling app exit
>>asynchronously. I rarely keep track of CWinThread objects, using other means of doing
>>shutdowns.
>
>If you don't join with all your threads before exiting, you have a race
>condition in your application termination.
Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.


Loading