Skip to content

Conversation

jeeeesper
Copy link
Contributor

@jeeeesper jeeeesper commented Sep 18, 2025

This is an attempt to make the library a bit more usable in a multi-threaded setting. I started to replace Rc<T>s with Arc<T>s where the wrapper type is supposed to be Send and/or Sync [1]. Of course, since we work with raw C-pointers and htslib in the background, it is quite the task to actually reason about thread-safety, so the assumption so far is that the C methods behave reasonable™. I need to mention that I am not very familiar with the underlying C code. So far, this PR also does not nearly solve all the problems related to thread-safety, frankly, it might introduce more. For example, I added Send/Sync implementations for some Header types, the soundness of which I have not really verified.

This all is motivated by the use of the library in my own multi-threaded program, and of course is therefore biased to what would be convenient for me (Send/Sync on Header or Reader/Writer types for example.) For getting a Send/Sync Reader/Writer, it is of course also possible to just create Wrapper types.

Maybe this will inspire some people to continue working on this, or I will do once I find the time. Maybe, this will even revive the discussion about how to solve this issue in general. I am very open to suggestions/discussions.

There are multiple issues that are mentioning this, most importantly maybe #293 .

[1] The performance penalty is, in my opinion, absolutely tolerable and greatly outweighs having to deal with segfault when doing something "simple" as using a parrallel iterator.

@coveralls
Copy link

coveralls commented Sep 18, 2025

Pull Request Test Coverage Report for Build 17828997000

Details

  • 28 of 31 (90.32%) changed or added relevant lines in 7 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.005%) to 83.715%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/bam/buffer.rs 1 2 50.0%
src/bam/header.rs 0 1 0.0%
src/bcf/mod.rs 9 10 90.0%
Totals Coverage Status
Change from base Build 16167570816: 0.005%
Covered Lines: 2745
Relevant Lines: 3279

💛 - Coveralls

@jeeeesper jeeeesper changed the title Reason about Send/Sync-ness of types and change Rcs to Arcs fix: Reason about Send/Sync-ness of types and change Rcs to Arcs Sep 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants