Skip to content

feat: impl Send/Sync for TreeSequence #297

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 24, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/trees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,9 @@ pub struct TreeSequence {
pub(crate) inner: MBox<ll_bindings::tsk_treeseq_t>,
}

unsafe impl Send for TreeSequence {}
unsafe impl Sync for TreeSequence {}

build_tskit_type!(TreeSequence, ll_bindings::tsk_treeseq_t, tsk_treeseq_free);

impl TreeSequence {
Expand Down Expand Up @@ -1612,3 +1615,19 @@ pub(crate) mod test_trees {
}
}
}

#[cfg(test)]
mod test_treeeseq_send_sync {
use crate::test_fixtures::treeseq_from_small_table_collection_two_trees;
use std::sync::Arc;
use std::thread;

#[test]
fn build_arc() {
let t = treeseq_from_small_table_collection_two_trees();
let a = Arc::new(t);
let join_handle = thread::spawn(move || a.num_trees());
let ntrees = join_handle.join().unwrap();
assert_eq!(ntrees, 2);
}
}