In my Tcl extension, a secondary thread is filling the Tcl event queue with events; the events contain pointers to structures with a dynamic life time.
What is the right strategy for ensuring that no events with dangling pointers to de-allocated structures remain in the event queue? I can prevent the secondary thread from creating new events; currently I call Tcl_DoOneEvent(TCL_DONTWAIT)
in a loop till it returns 0 (i.e., event queue is empty) after ensuring no new events can be created and before de-allocating the structure.
Is that the right way to do it?
On a related note, I am unsure of the purpose of Tcl_ThreadAlert()
: if this is needed after every call to Tcl_ThreadQueueEvent()
, why isn't the alert included in Tcl_ThreadQueueEvent()
?
Finally, my code does not call Tcl_CreateEventSource()
, since it doesn't seem to be needing a setup nor a check procedure as a second thread is involved. Is that cause for concern?