Am 10.08.2022 um 21:03 schrieb pd:
I was reading about the event loop to understand how it's implemented in tcl, in short I've learnt the event loop relies basically in three elements: the event generator called the notifier, the event loop itself called tcl_DoOneEvent and event
consumers which are essentially callback procs.
As far as I understand the notifier is a kind of wrapper over system events translating them to tcl events stored in a tcl event queue. The event loop Tcl_DoOneEvent consume events from that queue calling the "subscribed" procs, you init the even loop
by calling a special tcl command (vwait, fileevent...) indicating what proc is to be called when the right kind of event is processed in the event queue.
If this insight is more or less accurate I understand the notifier is system dependant (different for unix o windows) and related to system facilities to track events.
My question is how it is done?
I mean, It's said the tcl event loop is single thread but I suppose the notifier has to run on a different thread because it must be running all the time at the same time of tcl itself to detect events when happen and feed them to the tcl event queue
in an asynchronous way.
Other possibility is Tcl_DoOneEvent calls the notifier as first step to feed events to the queue and then process events in the queue until some condition is verified, but this may lead to an event queue never fully consumed. And also maybe a long wait
if notifier waits for events to come (for example in a unix select call)
regards
Well, "fully understanding" is a high demand, specially on all platforms.
On Windows, I can say, that the event system is often used to get an
event from the notifier thread to the TCL thread. So, you supposition is correct, that there are multiple threads. Nevertheless, the notifier
thread must deal intenally with the fact to get the information in the
main thread. The event system will only guarantee to get a callback, if
there is time for an event. Within this callback, the information is
taken from the event thread and the event is sheduled in TCL.
Maybe, some wiki examples
https://wiki.tcl-lang.org/page/Tcl%5FNotifyChannel
https://wiki.tcl-lang.org/page/Tcl%5FCreateEventSource
Enjoy,
Harald
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)