Comment 3 for bug 1751562

Revision history for this message
Tomas Hlavaty (q-tom-o) wrote :

this works:

(defun gettid (thread)
  (let (z
        (w (sb-thread::make-semaphore)))
    (sb-thread:interrupt-thread
     thread
     (lambda ()
       (setq z
             (with-open-file (s "/proc/thread-self/stat")
               (read s)))
       (sb-thread:signal-semaphore w)))
    (sb-thread:wait-on-semaphore w)
    z))

(mapcar (lambda (x) (cons (gettid x) (sb-thread:thread-name x)))
        (sb-thread:list-all-threads))

or instead of reading from /proc, use syscall:

            (sb-alien:with-alien ((fn (function sb-alien:int sb-alien:int)
                                       :extern "syscall"))
               (let ((a (sb-alien:alien-funcall fn 224)))
                 (if (minusp a)
                     (sb-alien:alien-funcall fn 186)
                     a))))))

this might be ok for development but not sure about production.
how dangerous is interrupt-thread used like this?