 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Guest
|
Posted: Mon Nov 20, 2006 1:16 am Post subject: Freeing a thread that WaitsForSingle(Multiple)Object(s) |
|
|
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
|
Posted: Mon Nov 20, 2006 3:39 pm Post subject: Re: Freeing a thread that WaitsForSingle(Multiple)Object(s) |
|
|
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
|
Posted: Wed Nov 22, 2006 9:13 am Post subject: Re: Freeing a thread that WaitsForSingle(Multiple)Object(s) |
|
|
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 |
|
 |
|
|
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
|
|