Skip to content

Commit 61b83ec

Browse files
committed
Remove one more race condition
1 parent c1f1a60 commit 61b83ec

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

src/core/haplotype.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,7 @@ impl<S: Symbol> Mutant<S> {
622622

623623
// synchronize swapping and deference with other threads
624624
let _guard = (*old_ptr)._defer_drop.lock();
625+
let _other_guard = (*new_ptr)._defer_drop.lock();
625626

626627
// replace the old reference with the new one inside the haplotype ref
627628
// this swaps the reference count of the old reference for the new one
@@ -1039,7 +1040,6 @@ mod tests {
10391040
let wt = Wildtype::new(symbols, &attribute_definition);
10401041

10411042
generation_provider.increment();
1042-
dbg!(&generation_provider);
10431043
let ht = wt.create_descendant(vec![0], vec![Nt::G]);
10441044
let ht_id = ht.get_block_id();
10451045
assert_eq!(wt.get_tree(), format!("('{}':1)wt;", ht_id));
@@ -1109,11 +1109,11 @@ mod tests {
11091109
) {
11101110
use rand::prelude::*;
11111111

1112-
let mut rng = rand::thread_rng();
1112+
let mut rng = rand::rng();
11131113

11141114
for i in 0..n_mutations {
1115-
let from = rng.gen_range(0..pop_size);
1116-
let to = rng.gen_range(0..pop_size);
1115+
let from = rng.random_range(0..pop_size);
1116+
let to = rng.random_range(0..pop_size);
11171117

11181118
let descendant = {
11191119
let ht = pop[from].lock().expect("Failed to lock ancestor.");
@@ -1134,8 +1134,8 @@ mod tests {
11341134
fn reader(pop: &[Mutex<HaplotypeRef<Nt>>], pop_size: usize, n_reads: usize, n_sites: usize) {
11351135
use rand::prelude::*;
11361136
for _ in 0..n_reads {
1137-
let mut rng = rand::thread_rng();
1138-
let index = rng.gen_range(0..pop_size);
1137+
let mut rng = rand::rng();
1138+
let index = rng.random_range(0..pop_size);
11391139
let ht = pop[index].lock().expect("Failed to lock haplotype.");
11401140
let sequence = ht.get_sequence();
11411141
assert_eq!(sequence.len(), n_sites);
@@ -1148,8 +1148,6 @@ mod tests {
11481148
use std::sync::Mutex;
11491149
use std::thread;
11501150

1151-
// TODO: investigate potential smallvec issue (unreachable code entered?)
1152-
11531151
let n_sites = 7;
11541152
let n_symbols = 4;
11551153

@@ -1169,8 +1167,10 @@ mod tests {
11691167
s.spawn(|| reader(&pop, pop_size, n_reads, n_sites));
11701168
});
11711169

1172-
let n_leaked = N_LEAKED.load(Ordering::Relaxed);
1173-
let n_dropped = N_DROPPED.load(Ordering::Relaxed);
1170+
thread::sleep(std::time::Duration::from_millis(100));
1171+
1172+
let n_leaked = N_LEAKED.load(Ordering::Acquire);
1173+
let n_dropped = N_DROPPED.load(Ordering::Acquire);
11741174
assert_eq!(
11751175
n_leaked, n_dropped,
11761176
"Number of leaked and dropped nodes should be equal."

src/runner.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ impl Runner {
427427
}
428428

429429
// adjust settings if needed
430-
if let Some(parameters) = self.setting.schedule.get_settings(generation) {
430+
if let Some(parameters) = self.settings.schedule.get_settings(generation) {
431431
log::info!("Adjust settings to:\n{}", parameters);
432432
self.simulations.iter_mut().for_each(|simulation| {
433433
simulation.set_parameters(parameters.clone());

0 commit comments

Comments
 (0)