Hey!

This is working great so far! I've managed to put together a tcp
server/client with a game loop side by side. The server spawns 2 threads
for each connection, one for commands and another for sending updates on an
interval. The render loop yields once per frame. The ctrl-c interrupt seems
to work still. And dti.so appears to work in csi and in compiled form. I
spent some time figuring out how to nicely cancel a thread with open
resources, and found thread-signal. My server thread looks like this:

(define (async-run-server!)
  (let ([listener (tcp-listen 0)])
    (print "listening on port " (tcp-listener-port listener))
    (handle-exceptions exn
      (begin
        (print "server thread exception: " exn)
        (print "closing listener port" )
        (tcp-close listener)) ;; handle-exceptions continuation called, and
thread finishes
      (let loop ()
        (let-values ([(in out) (tcp-accept listener)])
          (print "new connection")
          (write-line "hey" out)
          (thread-start! (cut async-send-update-packets! out))
          (thread-start! (cut async-listen-for-commands! in out))
          (loop))))))

And I can easily close it with (thread-signal! 'close) (thread-join!
server). I like it!

Thanks for all the help so far! I can think of some neat functions if this
gets into an egg. Like a function that spawns a group of tasks and waits
for one to finish.

Really cool to talk to the chicken creator himself by the way. Big fan
obviously :D

- Meowster


On Wed, Oct 7, 2026 at 2:35 PM Felix Winkelmann <[email protected]>
wrote:

> Hi!
>
> Here is an experimental approach:
>
> (import (scheme base))
>
> (declare (disable-interrupts) (uses scheduler))
>
> (define disable-timer-interrupts
>   (let ((old ##sys#interrupt-hook))
>     (lambda ()
>       (set! ##sys#interrupt-hook
>         (lambda (reason state)
>           (let loop ((reason reason))
>             (if (eq? 255 reason)
>                 (loop (##core#inline "C_i_pending_interrupt" #f))
>                 (old reason state))))))))
>
> If you compile this file, like this:
>
>   csc dti.scm -s -o dti.so
>
> You get a loadable file that installs a new interrupt-hook,
> which filters out timer-interrupts. We still need interrupt
> processing for handling signals, therefore we can't just disable
> them completely. This must be a separate file, so we can compile
> it without interrupt checks (interrupts in the interrupt handler
> would be a problem, naturally).
>
> Now you can load this into your file:
>
> (load "dti.so")
> (disable-timer-interrupts)
>
> And from there on context-switches should only happen on
> thread-yield! and I/O blocking. I only did some basic tests,
> perhaps you can try this and tell me whether it works for you.
>
> Once we make sure this works, we can think of a better packaging
> (as an egg, for example)
>
>
> cheers,
> felix
>
>

Reply via email to