
How much of a thread's memory is kept alive - after the thread has terminated - as long as a program holds on to the thread's `ThreadId'? The following ToDo comment in `PrelConc' seems to indicate that it is currently more than we really want:
data ThreadId = ThreadId ThreadId# -- ToDo: data ThreadId = ThreadId (Weak ThreadId#) -- But since ThreadId# is unlifted, the Weak type must use open -- type variables.
In combination with finalisers, this can be troublesome.
At the moment, the thread is kept completely alive by holding the ThreadId. Doing the weak pointer thing doesn't seem too hard. Something like this should work: data ThreadId = ThreadId (Weak# ThreadId#) mkThreadId :: ThreadId# -> IO ThreadId mkThreadId t = IO $ \s -> case mkWeak# t t (unsafeCoerce# 0#) s of (# s, w #) -> (# s, ThreadId w #) but you'll also need to update the other operations on ThreadIds. Cheers, Simon
participants (1)
-
Simon Marlow