4

I am trying to understand exactly how bound threads are implemented in Haskell.

I can instantiate multiple schedulers by passing in the -N[n] flag. Are these schedulers executing on individual OS threads?

By using forkOS from Control.Concurrent I am create a bound thread. Now, the documentation states that the thread will still be scheduled by the Haskell runtime-system, but it will appear as if it was created using pthread_create to any foreign functions. How is this actually realized? All foreign calls will be made from the same OS thread so that they can access thread-local state, but is there a chance that multiple bound threads may be pinned to the same OS thread?

I guess I am trying to understand when the actual OS threads are created, and how it is implemented that the Haskell threads appear to be bound.

Robert
  • 165
  • 10

1 Answers1

1

I can instantiate multiple schedulers by passing in the -N[n] flag. Are these schedulers executing on individual OS threads?

Yes.

All foreign calls will be made from the same OS thread so that they can access thread-local state, but is there a chance that multiple bound threads may be pinned to the same OS thread?

No, but I believe that OS thread may sometimes also be executing unbound Haskell threads. I believe those Haskell threads will be pushed to another scheduler (if there is one) before jumping into a foreign call.

Daniel Wagner
  • 145,880
  • 9
  • 220
  • 380