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 19161687300

Details

  • 34 of 36 (94.44%) changed or added relevant lines in 7 files are covered.
  • 20 unchanged lines in 6 files lost coverage.
  • Overall coverage decreased (-0.02%) to 81.912%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/bam/buffer.rs 1 2 50.0%
src/bam/header.rs 0 1 0.0%
Files with Coverage Reduction New Missed Lines %
src/bam/ext.rs 1 91.88%
src/bam/mod.rs 1 83.77%
src/tbx/mod.rs 1 82.24%
src/bam/buffer.rs 3 53.13%
src/bcf/record.rs 3 82.54%
src/bam/record.rs 11 75.44%
Totals Coverage Status
Change from base Build 18534912582: -0.02%
Covered Lines: 2785
Relevant Lines: 3400

💛 - 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
@jeeeesper jeeeesper force-pushed the use-arcs-in-records branch from e211ed9 to 907dabb Compare November 7, 2025 07:43
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