chicken-users
[Top][All Lists]
Advanced

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

Re: [Chicken-users] 1095 (prerelease) + some eggs


From: felix
Subject: Re: [Chicken-users] 1095 (prerelease) + some eggs
Date: Mon, 24 Feb 2003 23:44:44 +0100
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.0) Gecko/20020529

Joerg F. Wittenberger wrote:
Sorry

to follow up myself.  Stupid editing mistake.  Here the actual source
code I handed the compiler.

(define (askemos:run-tcp-server
         host port connection-handler
         maximum-semaphore name)
  (define request-queue (tcp-listen port))
  (define (exception-handler ex)
    (receive
     (title msg args rest) (exception->fields ex)
     (logerr "run-tcp-server (host ~a port ~a) ~a ~a ~a\n"
             host port title msg args)))
  (let loop ()
    (handle-exceptions
     ex (exception-handler ex)
     (receive
      (in-port out-port) (tcp-accept request-queue)
      (receive
       (local remote) (tcp-addresses in-port out-port)

                                               ^
`tcp-addresses' takes only a single argument. Normally, your
exception-handler should logerr something. Are you compiling in
safe mode?

       (if maximum-semaphore (semaphore-wait maximum-semaphore))
       (thread-start!
        (make-thread
         (lambda ()
           (handle-exceptions
            ex (exception-handler ex)
            (connection-handler in-port out-port remote)
            (if maximum-semaphore (semaphore-signal maximum-semaphore))
            (close-input-port in-port)
            (with-exception-handler
             ex (begin (close-output-port out-port) (loop)))))

Argh! Very wrong and very dangerous: the first arg to `with-exception-handler' 
must be
the handler itself and the second arg has to be a thunk. And then it may not 
simply
call `loop': that's in a different thread!
Don't use `with-exception-handler'. Use `handle-exceptions', it's safer.

           name))))
       (loop))))


One question: SRFI-18 says that an uncaught exception is stored
in the end-exception field of a thread and that the thread should
terminate. If the parent now join!s,
that uncaught exception will be raised. The problem is that errors
in child-threads are not reported to the user, which makes debugging
challenging, but not exactly fun.

Should the default exception handler still invoke `error'? No, because that 
would
throw back to toplevel (without storing something in the end-
exception field).

So what should it do?

1) Terminate silently, and store the end-exception
2) If not the primordial thread: Print a message to stderr and store it,
   otherwise invoke `error'
3) something else


cheers,
felix





reply via email to

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