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 eventconsumers 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 loopby 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.in an asynchronous way.
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
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 waitif notifier waits for events to come (for example in a unix select call)
regards
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 eventconsumers 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 loopby 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.
heinrichmartin wrote:
So Tcl does not have "the event loop", but stacked event loops, and
update does not enter "the event loop", but "the current event loop", which was new to me ...
I can see two improvements to vwait's doc now:
- This command enters the Tcl event loop to process events, ...
+ This command enters a newly created Tcl event loop to process events, ...
- In some cases the vwait command may not return immediately after
- varName is set. This happens if the event handler that sets varName
- does not complete immediately.
+ vwait does not return immediately after varName is set, but only
+ after all active event handlers have completed.
Both are already documented, just not adjacent to those two sections,
but a bit further within the man page:
man vwait:
...
To be clear, multiple vwait calls will nest and will not happen in
parallel. The outermost call to vwait will not return until all
the inner ones do.
...
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 463 |
Nodes: | 16 (2 / 14) |
Uptime: | 157:12:37 |
Calls: | 9,384 |
Calls today: | 4 |
Files: | 13,561 |
Messages: | 6,096,000 |