[gambit-list] res_query in the FFI
Christian
christian at pflanze.mine.nu
Fri Oct 13 11:00:59 EDT 2006
If you want to have multiple scheme threads call blocking C library
functions concurrently, not only the C library itself has to be
thread safe, but you also have to create a setup to dispatch the
scheme threads to OS threads (pthreads). Scheme threads are all
living within one OS threads, and calling into C without any further
help will block other scheme threads for the duration of the call. So
unless you're going to build such a dispatcher, there's no point in
making the C library reentrant, since everything is actually running
in one single OS thread.
So if you want to run DNS queries from multiple scheme threads in
parallel, you have these options:
- create said dispatcher, using either pthreads underneath (and
probably pipes for synchronisation), or pipes and fork. (At least for
the first variant I suggest using the cj-posix library I've announced
here some time ago (ask me for the newest version if you want to use
it, it now has more functionality). For the second you can also use
open-process and an external binary.) Thread/child pooling will be
necessary to make it efficient.
- look at what the Gambit host-info.. builtins are missing, and try
to improve on that by patching Gambit.
- port the DNS client library from "scheme underground" to Gambit
(http://www.scsh.net/resources/sunet.html)
The second option is probably the best for us all :). The third may
not be easy since the sunet libraries generally have many
dependancies on other scsh stuff (but it would be nice to have a port
of most of that stuff on Gambit some time). The first one may be the
easiest if you don't like to delve into too many lowlevel details.
I've recently tried to start playing with creating/accessing pthreads
from Gambit, but had to stop because of other work; I may return to
this sooner or later.
>What do I do with those? There's the type conversion thing in the
>manual for ECDIC characters which is incomplete,
I guess you mean EBCDIC. Why would this play a role with DNS, is DNS
using EBCDIC, or are you on a mainframe?
>and it seems as
>though the unicode support in Gambit is implemented through byte
>ports.
Hm, I'd say this is "wrong"; Gambit represents chars in the scheme
world as 4-byte (or optionally (at compile time) 2-byte (which
restricts it to a sub-range of current unicode)) values, and has to
convert to other encodings for port I/O.
From looking at the sources, I'd say there's no EBCDIC conversion in
the Gambit runtime except that hooks are ready for it (macros in
lib/os.h).
>Should I create a port? If so, can someone point me to a bit of the
>source code that'll get me started with that?
("No". But you may need ports to communicate readyness (and the
address of some struct) to another pthread when implementing
concurrency with pthreads.)
>Should I convert the answer string to some other format? I'd like to
>preserve any unicode characters that return from DNS.
For converting between UTF-8 encoded byte arrays and Scheme strings
just use the |utf8-string| type with c-lambda.
Christian.
More information about the Gambit-list
mailing list