Discussion:
ThreadId to Int
Andrew Martin
2017-11-01 14:53:46 UTC
Permalink
ThreadId has a Show instance that makes uses the FFI to turn a ThreadId to
a CInt:

instance Show ThreadId where
showsPrec d t =
showString "ThreadId " .
showsPrec d (getThreadId (id2TSO t))

foreign import ccall unsafe "rts_getThreadId" getThreadId :: ThreadId#
-> CInt

Can getThreadId be exported? This would make it possible to write a
Hashable instance for ThreadId, and it would make it possible to use a
ThreadId to index into an array (with modulus of course).

-Andrew Thaddeus Martin
Eric Seidel
2017-11-01 14:59:20 UTC
Permalink
I recently ran into this issue too, this would be a nice change!
Post by Andrew Martin
ThreadId has a Show instance that makes uses the FFI to turn a ThreadId to
instance Show ThreadId where
showsPrec d t =
showString "ThreadId " .
showsPrec d (getThreadId (id2TSO t))
foreign import ccall unsafe "rts_getThreadId" getThreadId :: ThreadId#
-> CInt
Can getThreadId be exported? This would make it possible to write a
Hashable instance for ThreadId, and it would make it possible to use a
ThreadId to index into an array (with modulus of course).
-Andrew Thaddeus Martin
_______________________________________________
Libraries mailing list
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
David Feuer
2017-11-01 17:04:02 UTC
Permalink
If there some concern a ThreadId could be bigger than an Int
somewhere/somewhen? Should it be Int64? Or could it be variable size,
suggesting whatever it is that backs SmallByteString?
Post by Andrew Martin
ThreadId has a Show instance that makes uses the FFI to turn a ThreadId to
instance Show ThreadId where
showsPrec d t =
showString "ThreadId " .
showsPrec d (getThreadId (id2TSO t))
foreign import ccall unsafe "rts_getThreadId" getThreadId :: ThreadId#
-> CInt
Can getThreadId be exported? This would make it possible to write a
Hashable instance for ThreadId, and it would make it possible to use a
ThreadId to index into an array (with modulus of course).
-Andrew Thaddeus Martin
_______________________________________________
Libraries mailing list
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Andrew Martin
2017-11-01 22:51:45 UTC
Permalink
I don't know. Since CInt is just a newtype wrapper around Int32, at the
moment it seems limited to that. I'm not sure about the actual data
structure that's being read from though. Int64 (or Word64) seems more
appropriate since it's certainly possible to fork more than 4 billion
threads in the lifetime of one haskell application. But my guess is that
it's currently just backed by Int32.
Post by David Feuer
If there some concern a ThreadId could be bigger than an Int
somewhere/somewhen? Should it be Int64? Or could it be variable size,
suggesting whatever it is that backs SmallByteString?
Post by Andrew Martin
ThreadId has a Show instance that makes uses the FFI to turn a ThreadId
instance Show ThreadId where
showsPrec d t =
showString "ThreadId " .
showsPrec d (getThreadId (id2TSO t))
ThreadId# -> CInt
Can getThreadId be exported? This would make it possible to write a
Hashable instance for ThreadId, and it would make it possible to use a
ThreadId to index into an array (with modulus of course).
-Andrew Thaddeus Martin
_______________________________________________
Libraries mailing list
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
--
-Andrew Thaddeus Martin
Carter Schonwald
2017-11-02 02:29:49 UTC
Permalink
Is it possible to make an execution that creates a threadid collision ?
Post by Andrew Martin
I don't know. Since CInt is just a newtype wrapper around Int32, at the
moment it seems limited to that. I'm not sure about the actual data
structure that's being read from though. Int64 (or Word64) seems more
appropriate since it's certainly possible to fork more than 4 billion
threads in the lifetime of one haskell application. But my guess is that
it's currently just backed by Int32.
Post by David Feuer
If there some concern a ThreadId could be bigger than an Int
somewhere/somewhen? Should it be Int64? Or could it be variable size,
suggesting whatever it is that backs SmallByteString?
Post by Andrew Martin
ThreadId has a Show instance that makes uses the FFI to turn a ThreadId
instance Show ThreadId where
showsPrec d t =
showString "ThreadId " .
showsPrec d (getThreadId (id2TSO t))
ThreadId# -> CInt
Can getThreadId be exported? This would make it possible to write a
Hashable instance for ThreadId, and it would make it possible to use a
ThreadId to index into an array (with modulus of course).
-Andrew Thaddeus Martin
_______________________________________________
Libraries mailing list
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
--
-Andrew Thaddeus Martin
_______________________________________________
Libraries mailing list
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Loading...