Hi Constantine, > I have a crazy idea to make a patch to PicoLisp that would allow > handling signals even during long native call (i. e. libcurl > download).
Yeah, I remember our discussion about this in IRC :) > The idea is to process signals immediately if PicoLisp not > in critical section of the code. I’m trying to modify `sig` function > in `main.l` as follows: > > (de void sig ((i32 . N)) > (if (val $TtyPid) > (kill @ N) > (set $Signal (+ (val $Signal) 1)) > - (let P (ofs $Signal (gSignal N)) > - (set P (+ (val P) 1)) ) ) ) > + (if (val $Protect) > + (let P (ofs $Signal (gSignal N)) > + (set P (+ (val P) 1)) ) > + (sighandler 0) ) ) ) > > However `sighandler` is undefined at this moment. I can’t move the > `sig` function after `sighandler`, since `sighandler` itself calls > `sig`. In such cases, a forward declaration is needed. You could write somewhere before `sig` (de void sighandler (any)) However: The reason for PicoLisp handling signals this way (i.e. not calling (sighandler 0) immediately, but accumulating all signals in the global $Signal array) is *not* to protect critical code sections (as indicated by $Protect). The reason is that a signal may occur at any moment, and 'sighandler' wants to run Lisp code. But Lisp code can be executed only at very well defined places in the code, when PicoLisp is not in the middle of building or modifying stack or heap structures, or even doing a garbage collection. At such safe places 'sigChk' is called, which may call 'sighandler' if any signals were accumulated meanwhile. An exception is 'sigChld', which handles the signal immediately. But this is safe too, as it neither calls Lisp code, nor does it modify any global structures. ☺/ A!ex -- UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe