bug-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug-gawk] Adding an API hook to enable a select extension


From: Eli Zaretskii
Subject: Re: [bug-gawk] Adding an API hook to enable a select extension
Date: Fri, 31 May 2013 21:48:09 +0300

> Date: Fri, 31 May 2013 14:15:42 -0400
> From: "Andrew J. Schorr" <address@hidden>
> Cc: address@hidden, address@hidden
> 
> BEGIN {
>    server["/inet4/tcp/0/127.0.0.1/12345"] = ""
>    server["/inet4/tcp/0/127.0.0.1/23456"] = ""
>    for (i in server)
>       PROCINFO[i, "READ_TIMEOUT"] = 0
>    while (length(server) > 0) {
>       for (i in server) {
>        if ((rc = (i |& getline x)) > 0)
>           printf "Server %s says: %s\n", i, x
>        else if (rc != TIMEOUT) {
>           printf "Error reading from %s: %s\n", i, ERRNO
>           close(i)
>           delete server[i]
>        }
>       }
>       sleep(1)
>    }
> }
> 
> If we omit the "sleep" function call, this will spin in a tight loop.

It doesn't have to.  The implementation of that loop could relinquish
CPU while the program waits.  There shouldn't even be a call to
'sleep' on the Awk program's level, that detail should be hidden under
the hood.  For example, we could have a new looping command, to be
used instead of 'while', which is suited for such event loops.

IOW, if the Awk programmer wants an event loop, she should just say
so, and Gawk will DTRT.  Let's not ask the programmer to program all
that explicitly.  Because if we do, we will next need to tell them to
handle interrupted system calls, signals, and whatnot.  If I need to
do all that, I'd rather code it all in C.

Awk is not a system programming language.  It is higher-level, so it
should conceal such details from the programmer.  Like it does with
memory allocation, for example.  IMO, at least.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]