[Bese-devel] Cooperative threads using continuations
szergling
senatorzergling at gmail.com
Wed Apr 18 10:59:06 UTC 2007
My last email is probably stuck in some spam box... so here it is
again, apologies if it did get through last time. I have also made
very minor changes in these files.
----------------------------------
Howdy folks,
I have had a chat over at #ucw about this issue previously, but still
haven't really resolved it. The issue is the call/cc interpreter in
arnesi does not really do tail calls, but seems to keep building up a
continuation that is passed along (CPS like?), growing as it goes, so
it uses up heap space.
I was playing with this, to try and demonstrate a cooperative
multitasking system with message passing. In many parts of this
system, and in code that uses it, a coding style making heavy use of
tail-calls can be most natural, so I would like some way to do
that.
For example, I've tried to write a simple echo or repl style server
(uses read-char-no-hang as non-blocking io) that has a (self
recursive) loop -- this kills my system very quickly. In clisp, it
segfaults. SBCL runs out of stack space too. Maybe I've missed a
tail-call position.
It's a bit tough because the code is all over the place. In the
meantime, I have cleaned up my code, and it now seems to run better
(as in, it doesn't die as soon as before). However, some code review
would be helpful.
I have attached here task.lisp which is the cooperative multitasking
code itself, queue.lisp (any queue implementation would do, but it
needs to be 'switch-able' between FIFO and LIFO at any time. If that
sounds contradictory, read the source code). Finally, there's some
sample code in test-subset.lisp (3 different examples -- run them
manually please, one after another, last one is the one that stresses
the system (depending on what lisp implementation you are using, you
might want to save all your work first)).
Please be gentle, I have just done a major tidy up, so bugs may be
lurking about. It is still quite incomplete, there's much much more that
can be done to make it usable. I have to say, when I first got
cooperative threads going, I just could not stop my evil laugh. The code
was just so small and simple. Unfortunately, it was in Scheme. Would
have been nice to have a first (for me) in CL, but Scheme was
cleaner...
Happy call/cc-ing!!
-------------- next part --------------
A non-text attachment was scrubbed...
Name: task.lisp
Type: application/octet-stream
Size: 6461 bytes
Desc: not available
URL: <https://mailman.common-lisp.net/pipermail/bese-devel/attachments/20070418/1507e00e/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: queue.lisp
Type: application/octet-stream
Size: 2352 bytes
Desc: not available
URL: <https://mailman.common-lisp.net/pipermail/bese-devel/attachments/20070418/1507e00e/attachment-0001.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test-subset.lisp
Type: application/octet-stream
Size: 2866 bytes
Desc: not available
URL: <https://mailman.common-lisp.net/pipermail/bese-devel/attachments/20070418/1507e00e/attachment-0002.obj>
More information about the bese-devel
mailing list