notifier

The notifier is a component of Tcl's event loop.

Disambiguation

Documentation

notifier%|%officia reference
The interaction between the I/O subsystem and the notifier

Description

DKF:

Tcl's notifier is the real core of how the event loop works. What it does is provide a bridge from the world of events that the OS can wait for to notifications that the rest of the event loop core uses to present the (apparently) simple callbacks it delivers.

To understand what it is doing, let us start by considering the simple case: an unthreaded system with one channel on Unix with one readable fileevent set upon it and no timer events. In this case, the notifier will basically just call select() with the only "interesting" file descriptor in the readable and exception sets being the FD that backs up the channel. The OS will then wait until either the FD has an error or becomes readable, when the select() call will return and the notifier will deliver that fact back up to the higher levels of the core. Even if a (non-fatal) signal turns up, it is handled here (usually by restarting the select(), though that's not the only way).

So far, so good.

Where things get more complex is when you're either on non-Unix platforms, or when you've got threads-on-Unix involved. To cut a long story short, those cases are very tricky because there are lots of special cases that have to be right or the notifier deadlocks unpredictably.

[more detail needed]

(2016-11-23) how does one use Tcl_SetNotifier? Can it be used in a Tcl extension? Or does it have to be called *before* Tcl_CreateInterp()?