[TUHS] Re {TUHS} Synchronous vs Asynchronous IO in Unix

Larry McVoy lm at mcvoy.com
Sat Sep 26 09:23:49 AEST 2015

On Fri, Sep 25, 2015 at 07:16:41PM -0400, Clem Cole wrote:
> Sadly I have heard a number of stories/expereiences like this.   That's why
> the original Posix.4 specification had a new API: asynchronous system traps
> (AST) similar to what most other real time systems have had such as RSX,
> VMS or VxWorks for that matter and true async I/O calls. 

Tcl (really tk, but tcl implements it) has this.  You bind an event to 
a subroutine and when the event happens it jumps into that subroutine,
just like an AST (with similar rules about calling context etc).

Mainly used for GUI programming where it fits nicely but one useful thing
is you can post fake events.  That makes it possible to write regressions
for gui code which is *awesome*.

--larry "still using tcl/tk after all these years" mcvoy

P.S.  We're not crazy, we implemented a C like language that compiles down
to tcl byte codes so we don't have to deal with tcl very much.  Here's
what that looks like, this is a little script that I use like

tail -f access.log | awk { print $1, $7 } | bk tclsh dns.l

It's like C with some perl goodness thrown in:

        string  buf;
        string  ip, file;

        while (buf = <>) {
                if (buf =~ /^\s*([0-9.]+)\s*$/) {
                        ip = $1;
                        buf = `host ${ip}`;
                        if (buf =~ /not found/ || buf =~ /has no PTR record/) {
                                printf("%s\n", ip);
                        } else unless (skip(buf)) {
                                buf =~ /([^ ]+$)/;
                                printf("%s\n", $1);
                buf =~ /([0-9.]+)\s+(.*)/;
                ip = $1;
                file = $2;
                if (file =~ /assets/) continue;
                if (file =~ /favicon/) continue;
                unless (exists("/home/bk/homepage-live/public/${file}")) {
                        file .= " (NOT FOUND)";
                buf = `host ${ip}`;
                if (buf =~ /not found/ || buf =~ /has no PTR record/) {
                        printf("%s %s\n", ip, file);
                if (skip(buf)) continue;
                buf =~ /([^ ]+$)/;
                printf("%s %s\n", $1, file);

skip(string host)
        switch (host) {
            case /crawl/:
            case /spider/:
            case /msnbot/:
                return (1);
        return (0);

More information about the TUHS mailing list