ThreadId to Int

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

ThreadId to Int

Andrew Martin
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

_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: ThreadId to Int

Eric Seidel-3
I recently ran into this issue too, this would be a nice change!

On Wed, Nov 1, 2017, at 10:53, Andrew Martin wrote:

> 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
> _______________________________________________
> Libraries mailing list
> [hidden email]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: ThreadId to Int

David Feuer
In reply to this post by Andrew Martin
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?

On Nov 1, 2017 10:54 AM, "Andrew Martin" <[hidden email]> wrote:
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

_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries


_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: ThreadId to Int

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.

On Wed, Nov 1, 2017 at 1:04 PM, David Feuer <[hidden email]> wrote:
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?

On Nov 1, 2017 10:54 AM, "Andrew Martin" <[hidden email]> wrote:
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

_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries




--
-Andrew Thaddeus Martin

_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: ThreadId to Int

Carter Schonwald
Is it possible to make an execution that creates a threadid collision ?

On Wed, Nov 1, 2017 at 6:52 PM Andrew Martin <[hidden email]> wrote:
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.

On Wed, Nov 1, 2017 at 1:04 PM, David Feuer <[hidden email]> wrote:
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?

On Nov 1, 2017 10:54 AM, "Andrew Martin" <[hidden email]> wrote:
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

_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries




--
-Andrew Thaddeus Martin
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries