The following problem may be just a reflection of my poor programming abilities, but I'm hope there's a good solution to this:<div><br></div><div>I run</div><div>$ gsc</div><div>> (load "server.scm")</div>
<div>-- starts: (thread 2), (thread 3)</div><div>> ; back here at primordial thread</div><div><br></div><div>The primordial thread is to let me have an interactive REPL</div><div>thread 2 does actual work</div><div>thread 3 listens on socket 8080 for remote commands to execute (this is is how I get vim/emacs to send commands to the repl, stuff like (load "foo.scm")); this command is then executed inside thread 2; (so thread 3 practically never has any exceptions, even when foo.scm doesn't parse properly)</div>
<div><br></div><div>The problem is -- foo.scm often has errors, either syntactical or run time errors.</div><div><br></div><div>Thus, thread #2 throws an exception, and I have to deal with it in the primordial thread, typically like</div>
<div><br></div><div>-- thread #1 --</div><div>> (void)</div><div>-- thread #2 --</div><div>exception blah blah blah</div><div>> ,(c 0)</div><div>> (void)</div><div>-- thread #1 --</div><div><br></div><div>Now, here's what I would like -- whenever thread 2 throws an exception, I want thread 3 to get notified, and somehow resume it when a new file gets loaded; however, if I don't load a new file, I want to be able to debug it in the REPL.</div>
<div><br></div><div>Better explained:</div><div><br></div><div>thread 2 throws an exception:</div><div><br></div><div>choice 1:</div><div>I go to REPL, type (void) into thread #1, and debug it manually</div><div><br></div>
<div>choice 2:</div><div>I don't care about the exception, I'm in emacs/vim, I send another (load "foo.scm") into thread 3, and thread 3 tells thread 2 to (a) resume and (b) (load "foo.scm")</div>
<div><br></div><div>Anyone else run into this problem? How did you solve it?</div><div><br></div><div>Thanks!</div><div><br></div><div><br></div><div><br><div class="gmail_quote">On Wed, May 20, 2009 at 6:29 AM, Marc Feeley <span dir="ltr"><<a href="mailto:feeley@iro.umontreal.ca">feeley@iro.umontreal.ca</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="im"><br>
On 20-May-09, at 12:03 AM, lowly coder wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Please see typescript (sorry, copy/paste not working in X right now)<br>
<br>
i have test.scm, which forks off a thread (<thread #2>) which forever does:<br>
  (pp 'yay); so I can see it print<br>
  (+ "asdf" 1) ; just to generate an error<br>
<br>
I'm running gsc with -:dar, so i want debugging support, for all threads, and get thrown into a REPL when an error occurs.<br>
<br>
Here are my questions:<br>
<br>
1) in my primordial thread, why do I have to execute some command (like "(void)") before I get thrown into the REPL in thread2? if everything is running concurrently, why does the error in thread2 not pop up immediately and get me thrown into a REPL?<br>

</blockquote>
<br></div>
That's because, by default, the REPL's interaction channel is the console and you have a single console.  So all threads interacting with the user (either REPL or calls to pp) are competing to get control of this single console to do their interaction.  A thread will acquire the console on entry to the REPL and relinquish the console when an expression is evaluated (most comma commands don't relinquish the console).  When the "acquire" operation succeeds and the thread is different from the previous thread that acquired the console, a message is displayed to indicate that the console is servicing the REPL of a different thread.<br>

<br>
The error doesn't immediately pop up because the primordial thread is running a REPL, so it has acquired exclusive access to the console.<div class="im"><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
2) in thread 2, after hitting ,(c 0) ... why don' i immediately get an "yay"? (if it's continuing from that error, it should jump back to the (pp 'yay))<br>
</blockquote>
<br></div>
Because the other thread (primordial thread) was waiting to acquire the console, and it acquired it at the moment thread 2 relinquished it.<div class="im"><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
3) after printing said 'yay', why do I have to hit (void) in the thread #1 before getting the error repl in thread 2? why doesn't the error immediately happen<br>
</blockquote>
<br></div>
Same as 2).  The console is being multiplexed fairly between the two threads that need to access it.<div class="im"><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
4) it seems like i'm ping-ponging between the two threads on the REPL. Is there anyway I can control this myself? (i.e. some command to jump me to thread1, some to jump me to thread2?)<br>
</blockquote>
<br></div>
You can use the ,(v #2) command to visit thread #2.  But that's mainly useful to interrupt a thread in mid execution.<br>
<br>
The ideal solution is to use an IDE which can present to the user several independent interaction windows. For example the Jazz IDE (Jedi).<br>
<br>
Alternatively, you can try the following "remote-debugging" code (for Unix + X11) which will pop up a new xterm for each REPL.  It is meant as a proof of concept, so I'm not sure how much mileage you can get out of it.<br>
<font color="#888888">
<br>
Marc<br>
<br>
</font><br><br>
<br></blockquote></div><br></div>