STG/CMM questions

Ben Gamari ben at smart-cactus.org
Fri May 29 15:22:00 UTC 2020


Daneel Yaitskov <dyaitskov at gmail.com> 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.

Cheers,

- Ben

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 487 bytes
Desc: not available
URL: <http://mail.haskell.org/pipermail/ghc-devs/attachments/20200529/35d5a28b/attachment.sig>


More information about the ghc-devs mailing list