<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
I'm sorry. It may be a matter of taste, but I don't like this solution.<br>
<br>
Also, starting a starting and synchronizing a thread is usually way <br>
faster than starting a subprocess. Kernels typically have special <br>
logic to support threads these days.<br>
<br>
Did you have a look at the spike I sent to the list? It missed the<br>
code in c-threads.c, but that can be found in the sqld-psql-c.plt<br>
package.<br>
<br>
Best wishes,<br>
<br>
--Hans<br>
<br>
Eli Barzilay schreef:
<blockquote cite="mid:18076.49841.192957.114480@kinyarwanda.ccs.neu.edu"
type="cite">
<pre wrap="">On Jul 17, Hans Oesterholt-Dijkema wrote:
</pre>
<blockquote type="cite">
<pre wrap="">The problem with C libraries is that they do not always provide
callback scenarios, nor other ways to divide up functions in smaller
parts to get some 'time slicing'.
</pre>
</blockquote>
<pre wrap=""><!---->
You should have *some* way to synchronize threads in C -- my point was
that the one that is easiest to implement in C is the right solution.
BTW -- here's an alternative:
Creating a subprocess is easy, and probably not much more expensive
than a thread. Specifically, it sounds like you're paying enough
price for DB operations that the difference between a system thread
and a system process would be insignificant. So it should be quite
easy to do what you want to do by running a mzscheme subprocess, and
communicate with it using stdin/stdout. This way you don't need to
deal with ports, tcp, or sockets. The subprocess doesn't even need to
load any special files -- you can feed it the code you want. Here's a
simple sketch:
(define (async/channel form)
(let-values ([(p pout pin perr)
(subprocess #f #f (current-error-port)
(find-system-path 'run-file)
"-mve" (format "(write (let () ~s))" form))]
[(c) (make-channel)])
(close-output-port pin)
(thread (lambda ()
(channel-put c (read pout))
(unless (sync/timeout 10 p)
(subprocess-kill p #f)
(unless (sync/timeout 10 p)
(subprocess-kill p #t)))))
c))
and an example:
(define (run-fib n)
(async/channel `(begin (define (fib n)
(if (<= n 1) n (+ (fib (- n 1)) (fib (- n 2)))))
(fib ,n))))
(map channel-get (map run-fib '(30 31 32 33)))
This can be made much better. (For example, you can send compiled
code over to the subprocess, you can add a mechanism that keeps
running processes around to avoid process creation overhead, you can
have state in threads, etc.)
</pre>
</blockquote>
</body>
</html>