Re: WaitForSingleObject() failing?



How so? The way it works is that the last thing the thread does before returning from the
thread is a PostMessage. Since nothing accesses the thread after that point, and it
accesses nothing else, the only issue is whether or not the process completes and does
ExitProcess before the thread actually finishes. As far as I can tell, all required
conditions are met for clean thread termination.
joe

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

>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.
Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.



Relevant Pages

  • 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 ... >when the outstanding thread count went to zero. ...
    (microsoft.public.vc.mfc)
  • Re: Function decorator that caches function results
    ... 'cache' and 'fn' are replaced by the objects they reference ... codes for all accesses to such objects. ... def wrapper: ... nested scopes; this is where the func_closure attribute is initialized). ...
    (comp.lang.python)
  • Re: [PATCH] Use MM_VM_SIZE in exit_mmap
    ... >> have seen this with the procfs code when process 1 accesses ... >> but does not tear its mm down. ... It's a natural outcome of reference ... send the line "unsubscribe linux-kernel" in ...
    (Linux-Kernel)
  • Re: Two more multithreading questions
    ... I have a class with an instance variable that is a reference to a JDialog. ... To ensure that my dialog closing thread always has a reference to the current dialog I created the instance variable with volatile. ... reference to any Object in the synchronize statement to do that? ... It doesn't have to be the reference to the Object that I am trying to protect as long as the accesses are all in synchronized blocks? ...
    (comp.lang.java.programmer)