CloseAntiFreeze required before thread destruction?

delphi package - automated exception handling
Post Reply
wprins
Posts: 7
Joined: Mon Mar 21, 2011 9:51 am

CloseAntiFreeze required before thread destruction?

Post by wprins »

Hi,

Is it mandatory to call CloseAntiFreeze before or on thread destruction (from the same thread that the InitAntiFreeze was called from), or is it OK to omit doing this and leave it up to the thread destruction? (That is, will thread destruction eventually also cause CloseAntiFreeze to be called automatically for a thread if required, or alternatively does it not matter if it's not called?)

(Background: I'm trying to plumb in some anti-freeze checking into a datasnap server but it's not exactly straightforward to ensure this gets called from the right thread as some cleanup/destruction calls of datasnap service objects seem to be handled not in the same thread they were created in for whatever reason.)

Thanks

Walter
madshi
Site Admin
Posts: 10753
Joined: Sun Mar 21, 2004 5:25 pm

Re: CloseAntiFreeze required before thread destruction?

Post by madshi »

That's a difficult question. AntiFreeze checking involves a window and an additional thread. The thread can be closed fine from the context of another thread. However, I'm not sure what happens to the window if the thread which called InitAntiFreeze closes down. I suppose the window probably dies. At that point probably also the whole freeze checking will die.

I suppose the best option would be to call InitAntiFreeze either from within the main thread. Or to create a dedicated thread for just freeze checking, to make sure the window survives as long as you want freeze checking to stay active. The anti freeze window is created in the context of the thread which calls InitAntiFreeze.
Post Reply