Skip to content

Commit

Permalink
Fixed bug in logging
Browse files Browse the repository at this point in the history
Previously would wait for scope to finish before starting the logging thread, causing deadlocks and low perf.
  • Loading branch information
pyprogrammer committed Mar 27, 2024
1 parent 3405e8e commit 60e7c95
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/simulation/initialized.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ impl<'a> Initialized<'a> {
(Some(log_sender), Some(log_receiver), true)
};

let handle = log_receiver
.and_then(|receiver| {
Self::make_logger(receiver, options.logging.clone())
.expect("Error creating Logger!")
.map(|mut exec_logger| std::thread::spawn(move || exec_logger.spawn()))
});

let summaries = std::sync::Arc::new(crossbeam::queue::SegQueue::new());

crate::shim::scope(|s| {
Expand Down Expand Up @@ -74,11 +81,9 @@ impl<'a> Initialized<'a> {

drop(log_sender);
});
if let Some(receiver) = log_receiver {
Self::make_logger(receiver, options.logging.clone())
.expect("Error creating Logger!")
.map(|mut exec_logger| std::thread::spawn(move || exec_logger.spawn()).join());
}

handle.map(|jh| jh.join());

Executed {
nodes: std::sync::Arc::into_inner(summaries)
.expect("Could not obtain unique access to summaries")
Expand Down

0 comments on commit 60e7c95

Please sign in to comment.