BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Freeing a thread that WaitsForSingle(Multiple)Object(s)

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi WinAPI
View previous topic :: View next topic  
Author Message
Guest






PostPosted: Mon Nov 20, 2006 1:16 am    Post subject: Freeing a thread that WaitsForSingle(Multiple)Object(s) Reply with quote



How to properly terminate and free a thread that waits for windows'
"callback", like when using WaitForSingleObject or
WaitForMultipleObjects?

Example:

While not Terminated do
AHandle := FindFirstChangeNotification(...)
WaitForSingleObject(AHandle, INFINITE)
...
FindCloseChangeNotification(AHandle)
end;

In this example, if the notification doesn't happen, the thread will
wait INFINITE, therefore I can't free it properly from an external
code. Wait functions, because of their blocking nature, (mostly) make
sense if used in a thread, so there must be a "common practise"
approach to this.

And probably a lame question, but is it safe to use Self.Free at the
end of Execute method? I've currently solved the issue by using a
custom message which the thread sends at the end of it's Execute
method, but I'm guessing that there's a "common practise" approach to
this, too.
Back to top
Guest






PostPosted: Mon Nov 20, 2006 3:39 pm    Post subject: Re: Freeing a thread that WaitsForSingle(Multiple)Object(s) Reply with quote



On Nov 19, 8:16 pm, bas...@verat.net wrote:
Quote:
And probably a lame question, but is it safe to use Self.Free at the
end of Execute method? I've currently solved the issue by using a
custom message which the thread sends at the end of it's Execute
method, but I'm guessing that there's a "common practise" approach to
this, too.

Ok, I've solved this by using TThread.FreeOnTerminate, but I still
haven't solved the first issue
Back to top
Riki Wiki
Guest





PostPosted: Wed Nov 22, 2006 9:13 am    Post subject: Re: Freeing a thread that WaitsForSingle(Multiple)Object(s) Reply with quote



Hoi

You need to repost your question in newsgroup b.p.d.nativeapi.win32 because
this newsgroup do not officially exist.

How to post to Delphi newsgroups:
<http://delphi.wikia.com/wiki/Delphi_Newsgroups>
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi WinAPI All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.