Article View: borland.public.cppbuilder.nativeapi
Article #8742Re: Thread WaitFor() ....waits forever
From: Remy Lebeau (TeamB)
Date: Wed, 22 Sep 2004 07:19
Date: Wed, 22 Sep 2004 07:19
34 lines
2586 bytes
2586 bytes
"Daniel Stevenson" <d.stevenson@ocreage.com.au> wrote in message news:415120dc@newsgroups.borland.com... > I sort of understand what you are implying but I'm not sure how > to stop my thread from being deadlocked. For one thing, try using TThread's WaitFor() method instead of calling WaitForSingleObject() directly. If you need to call WaitForSingleObject() then you should specify a timeout value and loop the call over and over. That way, you can pump the message queue manually between each iteration of the loop. > As far as I know, the Synchronize function is fairly > straight forward and should be able to be completed. Synchronize() uses window messages internally. In BCB 3-5, when Synchronize() is called, it uses SendMessage() to pass the specified method pointers to the the main thread to execute in a serialized manner. SendMessage() does not return control to the caller until the message has been processed. In BCB6, the method pointers are placed into a global list and then PostMessage() is called to notify the main thread that methods are waiting to be executed. The main thread runs through the list periodically, calling the stored methods one at a time. Either way, the main thread must process window messages in order to process Sychronize() requests properly. Synchronize() does not return control to the thread until the request is finished. If the main thread is blocked waiting on a thread to terminate, it still needs to process new messages while it is waiting, or else Synchronize() will block indefinately, and so will anything that is waiting on the thread to terminate. Gambit
Technical Details
Message-ID:
<41512711$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<415108cd$1@newsgroups.borland.com> <4151128c$1@newsgroups.borland.com> <415120dc@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,1897390e79ed181f X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <415108cd$1@newsgroups.borland.com> <4151128c$1@newsgroups.borland.com> <415120dc@newsgroups.borland.com> Subject: Re: Thread WaitFor() ....waits forever Date: Wed, 22 Sep 2004 00:19:05 -0700 Lines: 36 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1409 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 NNTP-Posting-Host: 68.69.17.41 Message-ID: <41512711$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1095837457 68.69.17.41 (22 Sep 2004 00:17:37 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail