[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-users] newbie thread questions?
From: |
F. Wittenberger |
Subject: |
Re: [Chicken-users] newbie thread questions? |
Date: |
Thu, 11 Dec 2008 13:01:10 +0100 |
Am Donnerstag, den 11.12.2008, 09:26 +0100 schrieb Basile STARYNKEVITCH:
> Hello All
>
>
> (my second mail of questions; I'm very newbie!)
>
> Apparently the Chicken thread package is continuation based and does not
> use pthread hence is not able to take of profit of several cores running
> several pthreads in the same unix process.
Yes.
> Are there any Chicken packages which are blocking? More specifically,
> can I run, using the http package, both HTTP client & HTTP server & some
> other user code without being blocked by a slow system call?
Don't know. Those I did not use so far.
> Can I suppose that every chicken thread syncrhonisation primitives (in
> particular mutex) are very cheap? My intuition is that they are
> user-level function without any system calls (ie to futex) inside!
You can.
That is, before you do, you want to include this in your code and
compile it with (disable-interrupts) and maybe some more declarations
you can lift from srfi-18.scm:
(global-set! 'mutex-unlock!
(lambda (mutex . cvar-and-to)
(##sys#check-structure mutex 'mutex 'mutex-unlock!)
(let ([ct ##sys#current-thread]
[cvar (and (pair? cvar-and-to) (car cvar-and-to))]
[timeout (and (fx> (length cvar-and-to) 1) (cadr cvar-and-to))] )
(dbg ct ": unlocking " mutex)
(when cvar (##sys#check-structure cvar 'condition-variable
'mutex-unlock!))
(##sys#call-with-current-continuation
(lambda (return)
(let ([waiting (##sys#slot mutex 3)]
[limit (and timeout (##sys#compute-time-limit timeout))] )
(##sys#setislot mutex 4 #f)
(##sys#setislot mutex 5 #f)
(##sys#setslot ct 8 (##sys#delq mutex (##sys#slot ct 8)))
(when cvar
(##sys#setslot cvar 2 (##sys#append (##sys#slot cvar 2)
(##sys#list
ct)))
(cond [limit
(##sys#setslot
ct 1
(lambda ()
(##sys#setslot cvar 2 (##sys#delq ct (##sys#slot
cvar 2)))
(if (##sys#slot ct 13) ; unblocked by timeout
(return #f)
(begin
(##sys#remove-from-timeout-list ct)
(return #t))) ) )
(##sys#thread-block-for-timeout! ct limit) ]
[else
(##sys#setslot ct 1 (lambda () (return #t)))
(##sys#setslot ct 3 'sleeping)] ) )
(unless (null? waiting)
(let* ([wt (##sys#slot waiting 0)]
[wts (##sys#slot wt 3)] )
(##sys#setslot mutex 3 (##sys#slot waiting 1))
(##sys#setislot mutex 5 #t)
(when (or (eq? wts 'blocked) (eq? wts 'sleeping))
(##sys#setslot mutex 2 wt)
(##sys#setslot wt 8 (cons mutex (##sys#slot wt 8)))
(when (eq? wts 'sleeping) (##sys#add-to-ready-queue
wt) ) ) ) )
(if (eq? (##sys#slot ct 3) 'running)
(return #t)
(##sys#schedule)) ) ) ) ) ))
Moreover please consider to try the attached scheduler.scm as a drop in
replacement for the current one. Especially when your are using
multithreaded code with a lot of i/o. Heavy HTTP/S communication are
the context where I found the shortcomings of the current scheduler.
YMMV however. When you did, please drop me a note about the effect in
your case.
Best regards
/Jörg
scheduler.scm
Description: Text Data