I'm just beginning with CL, I'm using CCL+Slime with Emacs v24 in Windows XP64. I am experiencing the following problem:
If I enter these three expressions in the REPL, I get the intended result, a file with the text "Something" in it:
(defparameter *file-out*
(open "e:/test.txt"
:direction :output
:if-exists :supersede
:if-does-not-exist :create))
(write-line "Something" *file-out*)
(close *file-out*)
But if the same code is in a text buffer and I evaluate the expressions one by one with C-c C-c, I get this error when evaluating the (write ...) statement:
Stream #<BASIC-FILE-CHARACTER-OUTPUT-STREAM ("e:/test.txt"/2616 UTF-8) #x2180C0A06D> is private to #<PROCESS worker(46) [Reset] #x2180BB558D>
[Condition of type SIMPLE-ERROR]
What can be the cause? Thanks for your help.
Edit:
I've found this in the backtrace, so the error seems to come from (CCL::CHECK-IOBLOCK-OWNER ...), which says the owner is "PROCESS Worker(31)":
0: (CCL::CHECK-IOBLOCK-OWNER #S(CCL::FILE-IOBLOCK :STREAM #<BASIC-FILE-CHARACTER-OUTPUT-STREAM ("e:/apps/gcj/2008-0-A-large-practice.out"/1600 UTF-8) #x2180AA709D> :UNTYI-CHAR NIL :INBUF ...))
Locals:
IOBLOCK = #S(CCL::FILE-IOBLOCK :STREAM #<BASIC-FILE-CHARACTER-OUTPUT-STREAM ("e:/apps/gcj/2008-0-A-large-practice.out"/1600 UTF-8) #x2180AA709D> :UNTYI-CHAR NIL :INBUF ...)
OWNER = #<PROCESS worker(31) [Reset] #x2180AA2B5D>
I did the following test to see who owns the file streams:
I opened two different files, file-out1 and file-out2, from the REPL, when trying to write to them from a test buffer with C-c C-c, I get the error saying the owner is "worker(12)".
I opened file-out1 from the test buffer with C-c C-c, when trying to writ to it from the test buffer or the REPL or anywhere else, I get the error saying the owner is "worker(30)".
I opened file-out2 from the test buffer with C-c C-c, when trying to writ to it from the test buffer or the REPL or anywhere else, I get the error saying the owner is "worker(31)".
I ran the test buffer (open, write, and close file) at once with C-c C-k and it worked.
Conclusion:
The REPL has a Worker process ID which doesn't change, but evaluations issued from a separate buffer (C-c C-c or C-c C-k) generate a new Worker process each time. Can someone explain the whole "Worker process" stuff?
Edit:
I re-tested in Linux and I obtain the same behavior than in Windows, to avoid confusion, I removed the parts about Linux
I got the answer from RG in comp.lang.lisp: the default behavior of (open ...) in CCL is to give the ownership of the stream to the process that first attempted an I/O operation on it. This can be overriden with the argument :sharing :lock. This is documented in http://ccl.clozure.com/ccl-documentation.html#CCL-Stream-Extensions.
I tested and now it works as expected.