Quantcast
Channel: OCaml - Topics tagged dune
Viewing all articles
Browse latest Browse all 521

Making my library thread-agnostic

$
0
0

I have a library that requires some thread-local state for correctness in the presence of threading, currently implemented as a Map from thread ids to the current value. This introduces a dependency on systhreads. However, the library does not itself depend on threading, and would work as well with a dummy implementation of Thread if it runs inside a single-threaded program. Is there a recommended way to make my library thread-agnostic and not depend on systhreads? I am especially looking for a solution at the level of dune.

I have two solutions in mind with their drawbacks:

  • Provide a functorial interface where the user supplies their desired implementation of the Thread module.
  • Choose between Thread and a dummy implementation at compilation using a preprocessor.

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 521

Trending Articles