summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2023-03-23 22:07:24 -0400
committerMarge Bot <ben+marge-bot@smart-cactus.org>2023-05-11 04:10:17 -0400
commit0a5139522394b901276ffa71283f01420e270746 (patch)
tree7b7c8e2f9523ca5bba6fb66eba7f1d9fafd1aa12
parent1e6861dd8612d8f71cc4635c4f73f84f316a6c7e (diff)
downloadhaskell-0a5139522394b901276ffa71283f01420e270746.tar.gz
base: Export GHC.Conc.Sync.fromThreadId
Closes #22706.
-rw-r--r--libraries/base/GHC/Conc/Sync.hs10
-rw-r--r--libraries/base/changelog.md1
2 files changed, 10 insertions, 1 deletions
diff --git a/libraries/base/GHC/Conc/Sync.hs b/libraries/base/GHC/Conc/Sync.hs
index ff40c4263f..715cde535e 100644
--- a/libraries/base/GHC/Conc/Sync.hs
+++ b/libraries/base/GHC/Conc/Sync.hs
@@ -33,6 +33,7 @@ module GHC.Conc.Sync
(
-- * Threads
ThreadId(..)
+ , fromThreadId
, showThreadId
, myThreadId
, killThread
@@ -148,11 +149,18 @@ garbage collected until you drop the 'ThreadId'. This misfeature would
be difficult to correct while continuing to support 'threadStatus'.
-}
+-- | Map a thread to an integer identifier which is unique within the
+-- current process.
+--
+-- @since 4.19.0.0
+fromThreadId :: ThreadId -> Word64
+fromThreadId tid = fromIntegral $ getThreadId (id2TSO tid)
+
-- | @since 4.2.0.0
instance Show ThreadId where
showsPrec d t = showParen (d >= 11) $
showString "ThreadId " .
- showsPrec d (getThreadId (id2TSO t))
+ showsPrec d (fromThreadId t)
showThreadId :: ThreadId -> String
showThreadId = show
diff --git a/libraries/base/changelog.md b/libraries/base/changelog.md
index 72b3cc9501..4ecba619ba 100644
--- a/libraries/base/changelog.md
+++ b/libraries/base/changelog.md
@@ -4,6 +4,7 @@
* Add `{-# WARNING in "x-partial" #-}` to `Data.List.{head,tail}`.
Use `{-# OPTIONS_GHC -Wno-x-partial #-}` to disable it.
([CLC proposal #87](https://github.com/haskell/core-libraries-committee/issues/87) and [#114](https://github.com/haskell/core-libraries-committee/issues/114))
+ * `GHC.Conc.Sync` now exports `fromThreadId :: ThreadId -> Word64`, which maps a thread to a per-process-unique identifier ([CLC proposal #117](https://github.com/haskell/core-libraries-committee/issues/117))
* Add `Data.List.!?` ([CLC proposal #110](https://github.com/haskell/core-libraries-committee/issues/110))
* `maximumBy`/`minimumBy` are now marked as `INLINE` improving performance for unpackable
types significantly.