Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8522631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T07:10:44+00:00 2026-06-11T07:10:44+00:00

If I create a thread using forkIO I need to provide a function to

  • 0

If I create a thread using forkIO I need to provide a function to run and get back an identifier (threadID). I then can communicate with this animal via e.g. the workloads, MVARs etc.. However, to my understanding the created thread is very limited and can only work in sort of a SIMD fashion where the function that was provided for thread creation is the instruction. I cannot change the function that I provided when the thread was initiated. I understand that these user threads are eventually by the OS mapped to OS threads.

I would like to know how the Haskell threads and the OS threads do interface. Why can Haskell threads that do completely different things be mapped to one and the same OS thread? Why was there no need to initiate the OS thread with a fixed instruction (as it is needed in forkIO)? How does the scheduler(?) recognize user threads in an application that could possibly be distributed? In other words, why are OS threads so flexible?

Last, is there any way to dump the heap of a selected thread from within the application?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T07:10:45+00:00Added an answer on June 11, 2026 at 7:10 am

    First, let’s address one quick misconception:

    I understand that these user threads are eventually by the OS mapped to OS threads.

    Actually, the Haskell runtime is in charge of choosing which Haskell thread a particular OS thread from its pool is executing.

    Now the questions, one at a time.

    Why can Haskell threads that do completely different things be mapped to one and the same OS thread?

    Ignoring FFI for the moment, all OS threads are actually running the Haskell runtime, which keeps track of a list of ready Haskell threads. The runtime chooses a Haskell thread to execute, and jumps into the code, executing until the thread yields control back to the runtime. At that moment, the runtime has a chance to continue executing the same thread or pick a different one.

    In short: many Haskell threads can be mapped to a single OS thread because in reality that OS thread is doing only one thing, namely, running the Haskell runtime.

    Why was there no need to initiate the OS thread with a fixed instruction (as it is needed in forkIO)?

    I don’t understand this question (and I think it stems from a second misconception). You start OS threads with a fixed instruction in exactly the same sense that you start Haskell threads with a fixed instruction: for each thing, you just give a chunk of code to execute and that’s what it does.

    How does the scheduler(?) recognize user threads in an application that could possibly be distributed?

    “Distributed” is a dangerous word: usually, it refers to spreading code across multiple machines (presumably not what you meant here). As for how the Haskell runtime can tell when there’s multiple threads, well, that’s easy: you tell it when you call forkIO.

    In other words, why are OS threads so flexible?

    It’s not clear to me that OS threads are any more flexible than Haskell threads, so this question is a bit strange.

    Last, is there any way to dump the heap of a selected thread from within the application?

    I actually don’t really know of any tools for dumping the Haskell heap at all, in multithreaded applications or otherwise. You can dump a representation of the part of the heap reachable from a particular object, if you like, using a package like vacuum. I’ve used vacuum-cairo to visualize these dumps with great success in the past.

    For further information, you may enjoy the middle two sections, “Conventions” and “Foreign Imports”, from my intro to multithreaded gtk2hs programming, and perhaps also bits of the section on “The Non-Threaded Runtime”.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a new System.Threading.Thread object using Jscript, but I can't get
If I create thread using Pthread library under Linux, I need to use function
Can I create a native thread on Windows running MRI, using the CreateThread API
I am using vc++ and creating a thread using CreateThread function .Can I restart
I want to create threads and assign different function for each thread using c#?
when you create thread using thread_create and pass the function, does the function goes
I am trying to create a new thread using an anonymous function but I
I create N threads using pthread_create on Linux/gcc. Each thread writes using for (;;)
I create a second thread to call a method that downloads several images using:
I am trying to create this QT gui using a thread but no luck.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.