Re: Features that can only be provided by the implementation?
- From: "Kaz Kylheku" <kkylheku@xxxxxxxxx>
- Date: 22 Apr 2006 11:24:47 -0700
Peter Seibel wrote:
So folks have been discussing the desirability of having a way to
change "Common Lisp" a lot lately. And other folks point out that
many, or even most, changes that folks want could be built *in* Common
Lisp. But not all. So my question is, what features that you think
might usefully be available to you in a Common Lisp environment have
to be provided by the CL implementation itself. With the help of a few
folks on #lisp I've got this list so far:
- multithreading
I wouldn't necessarily care to have complete multithreading support.
The important thing would be for the Lisp implementation to be
thread-safe and thread-aware where it needs to be. The actual support
for creating and synchronizing threads could be left to the foreign
function interface. It's too platform-specific, and doesn't belong in
the language. You want to avoid the Java disease.
For instance, on Win32, I'd use critical sections and events, which are
different from POSIX mutexes and condition variables. There are lots of
other differences. Structured exception handling versus POSIX signals
and cleanup handlers, thread cancelation, thread-specific storage
cleanup with destructors, etc.
If you go too far in wrapping the platform, you basically create a new
platform which has a different set of inefficiencies and pathologies on
every underlying platform that it's ported to. You either get a crappy
subset of all of their capabilities that you have to program against,
or else you get some deluxe interfaces with all the features, half of
which are emulated on each platform (and it's a different half on each
platform).
Here is an example of such a thing: Windows sockets and select(). The
fd_set on Win32 is implemented as an unordered array of handles rather
than a bitmask. This has a number of implications:
- the first argument to select is unnecessary (the number of
descriptors to poll) since the fd_set knows how many descriptors are in
its vector. Some Win32 code leaves that argument it as zero and breaks
when ported to "real" sockets.
- The FD_ISSET macro actually performs a linear search through the
array instead of directly accessing the bit.
- the "struct timeval" timeout isn't passed into the kernel directly,
but has to be recalculated into some other kind of time, like probably
the number of milliseconds to wait. In UNIX-like systems, it would go
right down into the system call: a struct timeval is known between
kernel and userland.
So basically, the intended design of select() is badly emulated for the
sake of keeping the interface compatible, while coupling it to a
different underlying kernel interface on which polling is done using
arrays of handles. This could be identified as a case of abstraction
inversion, because the abstracting is done at an inappropriately low
level.
So what I do on Windows sockets is to do something completely different
anyway. In a highly efficient server, I'd use IO completion ports. In
client code, I'd just crack open the fd_set and iterate it myself,
inverting the logic: rather than testing using FD_SET, just directly
process the descriptors placed in the array, violating the
encapsulation within an #ifdef WIN32 block of code. Or just use the
WSA*() functions.
Often it's better to just rewrite a high level chunk of application
code rather than to keep it the same and coerce the the dumber, lower
pieces into behaving the same way.
Any others? (I'm not counting things that could be provided using an
FFI, such as an interface to sockets.)
And, more importantly, to /platform-specific/ sockets (etc.) that let
you program properly for that platform.
.
- Follow-Ups:
- Re: Features that can only be provided by the implementation?
- From: Marcin 'Qrczak' Kowalczyk
- Re: Features that can only be provided by the implementation?
- From: Peter Seibel
- Re: Features that can only be provided by the implementation?
- References:
- Features that can only be provided by the implementation?
- From: Peter Seibel
- Features that can only be provided by the implementation?
- Prev by Date: Re: Beautiful code
- Next by Date: Re: Beautiful code
- Previous by thread: Re: Features that can only be provided by the implementation?
- Next by thread: Re: Features that can only be provided by the implementation?
- Index(es):
Relevant Pages
|
Loading