[plt-scheme] Re: Using LibFFI along with threads
On Jul 17, Noel Welsh wrote:
> - It should be possible to specify an OS thread to use. OS thread
> creation is quite expensive on some systems.
Wouldn't it make more sense to add threads when needed and keep some
after they're done? (Configurable like many popular servers.) Or are
you thinking of threads that hold some state?
> - The returned value should be a syncable value. This is a simpler
> programming model than the callback suggested in a previous thread.
I think that they're pretty much equivalent in ease of use -- and more
importantly, it's very easy to wrap a callback interface in a channel
(simplified, untested):
;; returns a channel, uses call/callback
(define (call/channel proc args)
(let ([c (make-channel)])
(call/callback proc args (lambda (res) (channel-put c res)))
c))
;; invokes a callback when ready, uses call/channel
(define (call/callback proc args callback)
(thread (lambda () (callback (channel-get (call/channel proc args))))))
Conclusion: C is a pain any way you look at it, so just go with
whatever is easier -- and then add bells in Scheme.
--
((lambda (x) (x x)) (lambda (x) (x x))) Eli Barzilay:
http://www.barzilay.org/ Maze is Life!