Skip to content

foreign-library: Which RTS to link against? #4815

Closed

Description

@treblacy

Thank you for the foreign-library addition, it is pretty sweet, it makes my life easier as the author of Calling Haskell Shared Libraries from C (Linux) 😆

Currently it links against the unthreaded GHC RTS. So there is potential that one day someone has a multi-threaded C program that uses a Haskell library built this way, calls Haskell functions from multiple threads concurrently, and there will be a problem. (The unthreaded RTS detects reentrancy and simply aborts the whole program with a "schedule: re-entered unsafely" message.)

I am not sure what I request instead:

  1. Add moar settings so a dev of a foreign-library can choose. But I'm not sure who is in the best position to choose, the Haskell foreign-library dev or the C program dev.

  2. Link against the threaded RTS across the board. But I'm not sure this harms no one; I don't even know the statistics of how many people have to avoid the threaded RTS.

Activity

  1. 23Skidoo commented on Oct 6, 2017

    @23Skidoo
    Member

    /cc @edsko

  2. edsko commented on Oct 9, 2017

    @edsko
    Contributor
  3. TravisWhitaker commented on Oct 16, 2017

    @TravisWhitaker
    Collaborator

    I'd like this feature too, and would lean towards option one. I think the Haskell library author should choose which RTS to link against, and if it's truly necessary to make this switchable a flag could be used.

    I'm interested in how the plumbing works for the foreign-import stanza; I was a bit surprised when ghc-options: ... -threaded ... didn't work.

  4. treblacy commented on Oct 16, 2017

    @treblacy
    Author

    I have a cunning plan! Produce both the unthreaded version and the threaded version.

  5. sergv commented on Jun 2, 2018

    @sergv
    Collaborator

    Just my 2 cents: even if C part has no concurrency whatsoever, it may be nice to still link Haskell shared library with the threaded runtime so that it will do its job faster. In a way, such a C program could delegate all the parallelism into Haskell.

  6. zlonast commented on Aug 30, 2026

    @zlonast
    Collaborator

    The problem was solved long ago in #5431

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions