Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Terminating Nameless Thread (SBCL)

Name: Anonymous 2012-01-24 2:15

Lisp newbie here. Say I have:
#<SB-THREAD:THREAD RUNNING {275C436B35}>
How would I terminate the thread in SLIME?

Name: Anonymous 2012-01-24 2:21

(list-all-threads)

Name: Anonymous 2012-01-24 3:03

>>1
#'sb-thread:terminate-thread

This is obviously non-portable, but since you didn't ask for a portable version (there are some libraries which make portability layers on top of implementation-specific implementations)...

How to find functions/symbols you're looking for with SLIME? In this case, you're looking for symbols which contain 'thread' in their name, so I type: thread in the REPL, press <tab>, and I get 2 completions, the first one being relevant: sb-thread:, press <tab> to select it then, press <tab> again, now you get more completions from within that package, the relevant ones seem to be:

sb-thread:destroy-thread                -f------ 1.15
sb-thread:terminate-thread              -f------ 1.15
sb-thread:interrupt-thread              -f------ 1.15

After looking at the first with M-., you can see

(defun destroy-thread (thread)
  #!+sb-doc
  "Deprecated. Same as TERMINATE-THREAD."
  (terminate-thread thread))

I then M-. on the terminate-thread calling form and see:

(defun terminate-thread (thread)
  #!+sb-doc
  "Terminate the thread identified by THREAD, by causing it to run
SB-EXT:QUIT - the usual cleanup forms will be evaluated"
  (interrupt-thread thread 'sb!ext:quit))


Now that is quite interesting, it seems a thread is terminated by making it run the usual quit function! Let's see what it has for interrupt-thread (M-.)


(defun interrupt-thread (thread function)
  #!+sb-doc
  "Interrupt the live THREAD and make it run FUNCTION. A moderate
degree of care is expected for use of INTERRUPT-THREAD, due to its
nature: if you interrupt a thread that was holding important locks
then do something that turns out to need those locks, you probably
won't like the effect. FUNCTION runs with interrupts disabled, but
WITH-INTERRUPTS is allowed in it. Keep in mind that many things may
enable interrupts (GET-MUTEX when contended, for instance) so the
first thing to do is usually a WITH-INTERRUPTS or a
WITHOUT-INTERRUPTS. Within a thread interrupts are queued, they are
run in same the order they were sent."
...


I suggest you get to know SLIME so you would have no problems whatsoever about finding out what each piece of code does. If completions don't work exactly like mine or if you have different keys bound, either learn your key chords or adjust your .emacs or SLIME-related code. If you can't view SBCL source code, either compile your own (what I did), or place the source code in the paths present within the FASLs (not preferable, although you could have Emacs/SLIME translate your paths).

Name: Anonymous 2012-01-24 12:11

>>3
Much appreciated.

Don't change these.
Name: Email:
Entire Thread Thread List