
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. emitAssign and CmmLocal are used everywhere, so they don't express logic particular to myThreadId function. was: return tso->id; now: currentTSOExpr = CmmReg currentTSOReg MyThreadIdOp -> \[] -> opAllDone $ \[res] -> do emitAssign (CmmLocal res) currentTSOExpr 2. Cmm macro for new TSO field is not found. I added to deriveConstants/Main.hs: ,closureField C "StgTSO" "trace_id" TSO.h: typedef struct StgTSO_ { ... StgClosure* trace_id; PrimsOps.cmm: gcptr p; p = StgTSO_trace_id(CurrentTSO); Linking error happens after make clean && ./boot && ./configure && make -j8 so I guess macros is not defined. Looks like such macros are not written to any file and it is hard to grep them. collect2: error: ld returned 1 exit status `cc' failed in phase `Linker'. (Exit code: 1) utils/iserv/ghc.mk:101: recipe for target 'utils/iserv/stage2/build/tmp/ghc-iserv' failed make[1]: *** [utils/iserv/stage2/build/tmp/ghc-iserv] Error 1 /home/dan/demo/haskell/compiler/ghc/rts/dist/build/libHSrts_thr_p.a(PrimOps.thr_p_o):function stg_getAdamTraceIdzh: error: undefined reference to 'StgTSO_trace_id' /home/dan/demo/haskell/compiler/ghc/rts/dist/build/libHSrts_thr_p.a(PrimOps.thr_p_o):function stg_getAdamTraceIdzh: error: undefined reference to 'n' collect2: error: ld returned 1 exit status `cc' failed in phase `Linker'. (Exit code: 1) utils/iserv/ghc.mk:105: recipe for target 'utils/iserv/stage2_p/build/tmp/ghc-iserv-prof' failed make[1]: *** [utils/iserv/stage2_p/build/tmp/ghc-iserv-prof] Error 1 Makefile:123: recipe for target 'all' failed -- Best regards, Daniil Iaitskov

Daneel Yaitskov
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
participants (2)
-
Ben Gamari
-
Daneel Yaitskov