[armedbear-devel] threads:interrupt-thread

Carlos Ungil carlos.ungil at gmail.com
Sat Sep 7 23:24:39 UTC 2013


Hello Erik,

I don't know how to debug java processes but I have an intuition about why those threads are not interrupted: they're never waiting.

See the example below: an interruption scheduled for the interpreter thread is only executed when I put the thread to sleep (and if the garbage collector runs in the meantime it's lost).

The reason why I cared about being able to interrupt the main thread was to run finalizers from there, to avoid concurrency issues in a foreign library. In the end I implemented an alternative solution using locks so I'm not really concerned about this problem anymore.

Regards,

Carlos

CL-USER(1): (let ((main (threads:current-thread)))
  (threads:make-thread (lambda ()
			 (threads:interrupt-thread main (lambda () (print "Hi there!"))))))
#<THREAD {3AF6EA95}>

CL-USER(2): (* 2 2)
4

CL-USER(3): (sleep 1)

"Hi there!"
NIL

CL-USER(4): (let ((main (threads:current-thread)))
  (threads:make-thread (lambda ()
			 (threads:interrupt-thread main (lambda () (print "Hi there!"))))))
#<THREAD {CE5A31A}>

CL-USER(5): (gc)
462843184

CL-USER(6): (sleep 1)
NIL


On 06/09/2013, at 21:49, Erik Huelsmann <ehuels at gmail.com> wrote:

> Hi Carlos,
> 
> > is there a reason why interrupt-thread doesn't seem to run the requested function in some cases? The following code tries to run a function in each existing thread (the variable *output* logs the calls that we try to run and the ones that are actually run).
> 
> Looking at your  code, there may be multiple causes for the strings not showing up in the output. Frst of all, there's a problem with concurrency in your code: pushing into the *output* variable across threads isn't thread safe. The other reason for the code not being executed could be a bug: the code "checks manually" whether the thread interrupt has been invoked and executes the function(s) handed over. Maybe these threads land in loops that do not check this condition.
> > (defvar *output*)
> >
> > (defun test-run ()
> >   (setf *output* nil)
> >   (threads:mapcar-threads
> >    (lambda (thread)
> >      (push (format nil "~A : calling" thread) *output*)
> >      (threads:interrupt-thread thread
> >       (lambda () 
> > (push (format nil "~A : running" thread) *output*))))))
> >
> > (defun test-report ()
> >   (format t "~{~A~%~}" (reverse *output*)))
> >
> > Running in the command line:
> 
> [snip]
> 
> >
> > I can understand that the thread "TEST-RUN" that I create to run the function might disappear before it gets to run the function as requested, or maybe the reason is that a thread can't interrupt itself by design... But why doesn't the thread "interpreter" run the function?
> >
> > Running in slime there are many threads present, and most of them will respond as expected. But "TEST-RUN", "interpreter" and "reader-thread" won't.
> 
> Can you interrupt the reader-thread and interpreter thread in a java debugging environment and tell me what the stack trace is when you send the signal that isn't being processed? Maybe the answer turns out to be really obvious.
> Thanks!
> 
> Bye,
> 
> 
> Erik.
> 




More information about the armedbear-devel mailing list