Discussion:
Freeing a thread that WaitsForSingle(Multiple)Object(s)
(too old to reply)
b***@verat.net
2006-11-19 19:16:59 UTC
Permalink
Raw Message
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.
b***@verat.net
2006-11-20 09:39:05 UTC
Permalink
Raw Message
Post by b***@verat.net
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
Riki Wiki
2006-11-22 06:46:38 UTC
Permalink
Raw Message
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>

Loading...