Subject: Re: call/cc
From: rpw3@rpw3.org (Rob Warnock)
Date: Sat, 08 Apr 2006 05:50:16 -0500
Newsgroups: comp.lang.lisp
Message-ID: <dcmdnWwX6K_1CKrZRVn-iw@speakeasy.net>
Philippe Lorin  <palpalpalpal@gmail.com> wrote:
+---------------
| - There doesn't seem to be much documentation about CMUCL's mp package. 
| The best I found is:
| http://www.trakt7.net/cmucl%20and%20multiprocessing
+---------------

That one's pretty good, based as it is on the actual output of
DESCRIBE, though it appears to be based on CMUCL-18e, whereas
CMUCL-19c is current, so you might want to repeat the DESCRIBE
for yourself with whichever version you're using.

+---------------
| Isn't there anything better, more synthetic?
+---------------

For questions not answered by DESCRIBE, the easiest thing
[and most accurate] would be to just read the code in the
CMUCL source distribution [which is what I did, once I started
using it seriously], in the file "src/code/multi-proc.lisp".

But if you want something *less* accurate but more narrative  ;-}  ;-}
you might try one of these:

    http://www.mikemac.com/mikemac/clim/clim-sys.html
    http://www.lispworks.com/reference/lwl42/CLIM-U/html/climguide-330.htm
    http://alu.cliki.net/com-metacircles-clim-sys-mp

+---------------
| - The following:
| (mp:make-process (lambda () (print 1) (terpri)))
| works as I'd expect (it prints "1") in a REPL run from the console, or 
| in the *inferior-lisp* buffer in Slime, but in the *slime-repl cmucl* 
| buffer it doesn't print anything. Why?
+---------------

Sorry, I don't use SLIME, so I can't comment.

+---------------
| - Finally, while your code looks OK, it doesn't seem to work for me; 
| maybe I'm missing something. If I do:
|    (defun p (x) (print x) (terpri))
|    (defparameter *c*
|       (cstart
|        (p 1)
|        (yield)
|        (p 2)))
| It immediately runs all the body, writing:
|    1
|    2
+---------------

Oops! Sorry, I *did* say it was untested!  ;-}

I've actually never used MP:DISABLE-PROCESS and MP:ENABLE-PROCESS
before [all the threads I write run to completion (possibly blocking
on I/O)], and I didn't notice that MP:DISABLE-PROCESS *doesn't* give
up the CPU. I think you'll find things work better for you if you
change the definition of YIELD from:

    (defun yield ()
      (mp:disable-process mp:*current-process*))

to:

    (defun yield ()
      (mp:disable-process mp:*current-process*)
      (mp:process-yield))

Testing:

    cmu> (defparameter *c*
	   (cstart
	   (p 1)
	   (yield)
	   (p 2)))

    *C*
    cmu> (progn (cstep *c*) (mp:process-yield))

    1 
    NIL
    cmu> (progn (cstep *c*) (mp:process-yield))

    2 
    NIL
    cmu> 

Is that more like what you expected?


-Rob

p.s. If you try typing just (CSTEP *C*) to the REPL you'll quickly
discover why I did (PROGN (CSTEP *C*) (MP:PROCESS-YIELD)) instead!  ;-}

p.p.s. Also note that I typo'd MP:ENABLE-PROCESS & MP:DISABLE-PROCESS
as MP-ENABLE-PROCESS & MP-DISABLE-PROCESS in my original posting. Oops.

-----
Rob Warnock			<rpw3@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607