[gambit-list] Thread question

Marc Feeley feeley at iro.umontreal.ca
Mon Oct 5 08:54:47 EDT 2009

On 5-Oct-09, at 12:50 AM, Mikael More wrote:

> Dear Marc,
> May threads be GC:ed in case they are started, but there's no  
> variable references to them?
> I.e., might (##gc) after having evaluated
> (thread-start! (make-thread (lambda () (let loop () (print ".")  
> (thread-sleep! 0.5) (loop)))))
> stop the thread?

No.  The run queue managed by the thread scheduler is part of the root  
set.  The timeout queue, which is used by thread-sleep! and other  
operations with a timeout, is also part of the root set.  So if a  
thread is "runnable" or it might wake up after a timeout period has  
elapsed, then it will not be collected.

Unreachable blocked threads *can* be garbage collected (for example a  
thread blocked on a mutex that is unreachable).  I tried writing a  
program which exhibits this behavior but couldn't, so I suspect there  
is a spurious reference to the thread and I need some time to track  
this down.

> For a side question, the documentation says "The thread’s execution  
> consists of a call to thunk with the initial continuation. This  
> continuation causes the (then) current thread to store the result in  
> its end-result field, abandon all mutexes it owns, and finally  
> terminate.". By end-result, do you mean that the return value of the  
> thread thunk is stored somehow in the thread variable?

Yes.  If the result terminated normally, the result is accessible with  
the thread-join! procedure.


More information about the Gambit-list mailing list