From: Vladimir T. <vtz...@gm...> - 2009-07-11 21:16:15
|
On 7/11/09, Tobias C. Rittweiler <tc...@fr...> wrote: > > I tried to use the new thread interface in Clisp's SWANK backend, and I > have come across a few minor issues, and one serious bug: > > * The lock-related functions are consistently called MUTEX-foo, but > the macro to grab a mutex is called WITH-LOCK. Does with-mutex-lock sound better? Sam? > * I don't like that (thread-name (make-thread #'(lambda ()))) returns > #<UNBOUND>, as you cannot use (or (thread-name ...) "SOME-DEFAULT") > this way. Why don't you name the thread? I think :name should be mandatory - like for make-mutex and make-exemption. This helps debugging and does not annoy too much. > * I think the default print-object method specializing on threads > should print whether the thread is currently running, or has been > stopped. While it may be useful for quick check - there is thread-active-p for this purpose. (notice that current state of thread (running or finished) may change while you read it - do not rely on it- it is just for debugging). > Now to a much more serious issue: > > * If I run the file below, clisp exits with "Aborted". I'm on > Linux-x86/32, compiled clisp from CVS four hours ago. Have threads > and weak-hashtables been tested? Thanks. weak-hashtables and threads were not tested together. The problem is somehow related to: http://sourceforge.net/tracker/?func=detail&aid=1472478&group_id=1355&atid=101355 While not identical they share quite in common. Threads, mutexes, exemptions (and finalizers) will cause problems when mixed with weak pointers. As for current version of clisp - do not use them together. I'll work on fixing this. Vladimir > PS. > > (defvar *thread-plist-table-lock* > (mp:make-mutex :name "THREAD-PLIST-TABLE-LOCK")) > > (defvar *thread-plist-table* (make-hash-table :weak :key) > "A hashtable mapping threads to a plist.") > > (defvar *thread-id-counter* 0) > > (defun thread-id (thread) > (mp:with-lock (*thread-plist-table-lock*) > (or (getf (gethash thread *thread-plist-table*) 'thread-id) > (setf (getf (gethash thread *thread-plist-table*) 'thread-id) > (incf *thread-id-counter*))))) > > (defvar *thread* (make-thread (lambda () (loop (sleep 1))))) > > (thread-id *thread*) > > (thread-interrupt *thread* :function t) > > (setq *thread* nil) > > (gc) > |