Skip to content

Commit 4871072

Browse files
authored
feat: impl Send/Sync for TreeSequence (#297)
BREAKING CHANGE: implementing a new trait will break code assuming that the type is not thread save (!Sync + !Send).
1 parent 7e42e9a commit 4871072

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/trees.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -961,6 +961,9 @@ pub struct TreeSequence {
961961
pub(crate) inner: MBox<ll_bindings::tsk_treeseq_t>,
962962
}
963963

964+
unsafe impl Send for TreeSequence {}
965+
unsafe impl Sync for TreeSequence {}
966+
964967
build_tskit_type!(TreeSequence, ll_bindings::tsk_treeseq_t, tsk_treeseq_free);
965968

966969
impl TreeSequence {
@@ -1612,3 +1615,19 @@ pub(crate) mod test_trees {
16121615
}
16131616
}
16141617
}
1618+
1619+
#[cfg(test)]
1620+
mod test_treeeseq_send_sync {
1621+
use crate::test_fixtures::treeseq_from_small_table_collection_two_trees;
1622+
use std::sync::Arc;
1623+
use std::thread;
1624+
1625+
#[test]
1626+
fn build_arc() {
1627+
let t = treeseq_from_small_table_collection_two_trees();
1628+
let a = Arc::new(t);
1629+
let join_handle = thread::spawn(move || a.num_trees());
1630+
let ntrees = join_handle.join().unwrap();
1631+
assert_eq!(ntrees, 2);
1632+
}
1633+
}

0 commit comments

Comments
 (0)