GHC.Conc.Sync currently says
-- ToDo: data ThreadId = ThreadId (Weak ThreadId#)
-- But since ThreadId# is unlifted, the Weak type must use open
-- type variables.
That seems unlikely to happen, especially now that we have threadStatus (which needs to be able to determine how a thread died).
However, the condition that comment waits for has arrived—we can now have values of type Weak# ThreadId#, which are just slightly more efficient than the Weak# ThreadId values we could have before. No, I don't know why that was considered important. Anyway, the question arises as to whether Asyncs should hold their ThreadId#s weakly. That would mean doing something like
data WeakThreadId = WeakThreadId
{ tid_number :: !Word64
, tid_weak :: Weak# ThreadId#
}
The thread ID number is needed to support compareAsyncs and the Ord (Async a) instance.
Making this change would necessitate an API change: the asyncThreadId function (defined as a field accessor) would have to be removed, in favor of something like
asyncThreadIdMaybe :: Async a -> IO (Maybe ThreadId)
One big question in my mind: garbage collecting Weak#s can be pretty expensive. Is releasing threads earlier worth that cost?
GHC.Conc.Synccurrently saysThat seems unlikely to happen, especially now that we have
threadStatus(which needs to be able to determine how a thread died).However, the condition that comment waits for has arrived—we can now have values of type
Weak# ThreadId#, which are just slightly more efficient than theWeak# ThreadIdvalues we could have before. No, I don't know why that was considered important. Anyway, the question arises as to whetherAsyncs should hold theirThreadId#s weakly. That would mean doing something likeThe thread ID number is needed to support
compareAsyncsand theOrd (Async a)instance.Making this change would necessitate an API change: the
asyncThreadIdfunction (defined as a field accessor) would have to be removed, in favor of something likeOne big question in my mind: garbage collecting
Weak#s can be pretty expensive. Is releasing threads earlier worth that cost?