chicken-hackers
[Top][All Lists]
Advanced

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

Re: [Chicken-hackers] [PATCH 1/2] tcp: disable interrupts


From: Jörg F . Wittenberger
Subject: Re: [Chicken-hackers] [PATCH 1/2] tcp: disable interrupts
Date: 17 Mar 2013 15:27:29 +0100

On Mar 17 2013, Florian Zumbiehl wrote:

Somehow, this feels to me like you are applying test driven development
techniques to concurrency correctness. Are you sure that your reasoning is
correct and reliable and future-proof? Are the assumptions you make about
the compiler true now for sure and can that be expected to stay that way
even with new optimizations, say?
...
As for the robustness of the code in the face of future changes, I would
submit that the current code being defective could be considered evidence
that the current approach is indeed too fragile. Not only could it break
inadvertently, it _did_ already break.

+1

the rcp code ougth to be re-written at least for use with srfi-18

this remindes me… at one point I fixed smth in srfi-18
will have to dig it out. mutex-lock! was somewhat broken.

I can now only paste my current version.


(define mutex-lock! (lambda (mutex . ms-and-t)
   (##sys#check-structure mutex 'mutex 'mutex-lock!)
   (let* ([limitsup (pair? ms-and-t)]
           [limit (and limitsup (compute-time-limit (car ms-and-t) 
'mutex-lock!))]
           [threadsup (fx> (length ms-and-t) 1)]
           [thread (and threadsup (cadr ms-and-t))] )
     (when thread (##sys#check-structure thread 'thread 'mutex-lock!))
     (##sys#call-with-current-continuation
      (lambda (return)
         (let ([ct ##sys#current-thread])
           (define (switch)
             (##sys#setslot mutex 3 (##sys#append (##sys#slot mutex 3) (list 
ct)))
             (##sys#schedule) )
           (define (check)
             (when (##sys#slot mutex 4) ; abandoned
(return (##sys#signal (##sys#make-structure 'condition '(abandoned-mutex-exception) (list (##sys#slot mutex 1))))) ) )
           (define (assign)
             (let ((abd (##sys#slot mutex 4)))
               (if (and threadsup (not thread))
                   (begin
                     (##sys#setislot mutex 2 #f)
                     (##sys#setislot mutex 5 #t) )
                   (let* ([t (or thread ct)]
                          [ts (##sys#slot t 3)] )
                     (if (or (eq? 'terminated ts) (eq? 'dead ts))
                         (begin
                           (##sys#setislot mutex 2 #f)
                           (##sys#setislot mutex 5 #f)
                           (##sys#setislot mutex 4 #t))
                         (begin
                           (##sys#setslot mutex 2 t)
                           (##sys#setislot mutex 5 #t)
                           (##sys#setslot t 8 (cons mutex (##sys#slot t 8))) ) 
) ) )
               (return
                (if abd
(##sys#signal (##sys#make-structure 'condition '(abandoned-mutex-exception) (list (##sys#slot mutex 1))))
                    #t))))
           (dbg ct ": locking " mutex)
           (cond [(not (##sys#slot mutex 5))
                  (assign) ]
                 [limit
                  (check)
                  (##sys#setslot
ct 1 (lambda ()
                     (if (##sys#slot ct 13)  ; unblocked by timeout
                         (return #f)
                         (begin
                           (##sys#remove-from-timeout-list ct)
                           (assign))) ))
                  (##sys#thread-block-for-timeout! ct limit)
                  (switch) ]
                 [else
                  (##sys#setslot ct 3 'sleeping)
                  (##sys#setslot ct 11 mutex)
                  (##sys#setslot ct 1 assign)
                  (switch) ] ) ) ) ) ) ) )


Are there any problems with disabling interrupts? The potential for
starvation mentioned by Felix should be quite easy to fix by scheduling
manually after every write() or read() call and not just on
EAGAIN/EWOULDBLOCK/EINTR, I think?!




reply via email to

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