STG/CMM questions

Ben Gamari ben at
Fri May 29 15:22:00 UTC 2020

Daneel Yaitskov <dyaitskov at> writes:

> Hi,
> There are 2 questions:
> 1. How to decipher myThreadId implementation in STG?
> What is the principle behind STG version?
> Is it matching first field from TSO by type?
> "id" is not mentioned anyhow and there is no offset to id field.
> The whole TSO struct is just mentioned.
See the Haddocks for GHC.Conc.Sync.ThreadId. In short, ThreadId# (which
is what the myThreadId# primop returns) is an opaque thread identifier
which is represented by a pointer to a TSO. The Show instance for
ThreadId prints the `id` field of the TSO. However, we don't directly
expose the `id` field to the user; you merely get Eq and Ord instances.
Admittedly, this may be a problem for users wanting to use, e.g., a
HashMap keyed on ThreadId. Perhaps we could expose the
GHC.Conc.Sync.getThreadId to the user. However, using this correctly
would take great care.


- Ben

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 487 bytes
Desc: not available
URL: <>

More information about the ghc-devs mailing list