Skip to content

Commit

Permalink
LS: Fix hangs while spawning diagnostics tasks
Browse files Browse the repository at this point in the history
commit-id:032d1a59
  • Loading branch information
mkaput committed Nov 18, 2024
1 parent d62ea56 commit 4a75102
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
2 changes: 0 additions & 2 deletions crates/cairo-lang-language-server/src/lang/diagnostics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,6 @@ impl DiagnosticsControllerThread {

/// Shortcut for spawning a worker task which does the boilerplate around cloning state parts
/// and catching panics.
// FIXME(mkaput): Spawning tasks seems to hang on initial loads, this is probably due to
// task queue being overloaded.
fn spawn_worker(&self, f: impl FnOnce(ProjectDiagnostics, Notifier) + Send + 'static) {
let project_diagnostics = self.project_diagnostics.clone();
let notifier = self.notifier.clone();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@
//! The thread pool is implemented entirely using
//! the threading utilities in [`crate::server::schedule::thread`].

use std::cmp::min;
use std::num::NonZero;
use std::thread::available_parallelism;

use crossbeam::channel::{Receiver, Sender, bounded};
use crossbeam::channel;

use super::{Builder, JoinHandle, ThreadPriority};

Expand All @@ -38,7 +37,7 @@ pub struct Pool {
// make sure to keep `job_sender` above `handles`
// so that the channel is actually closed
// before we join the worker threads!
job_sender: Sender<Job>,
job_sender: channel::Sender<Job>,
_handles: Vec<JoinHandle>,

parallelism: NonZero<usize>,
Expand Down Expand Up @@ -67,16 +66,15 @@ impl Pool {

let threads = available_parallelism().map(usize::from).unwrap_or(DEFAULT_PARALLELISM);

// Channel buffer capacity is between 2 and 4, depending on the pool size.
let (job_sender, job_receiver) = bounded(min(threads * 2, DEFAULT_PARALLELISM));
let (job_sender, job_receiver) = channel::unbounded();

let mut handles = Vec::with_capacity(threads);
for i in 0..threads {
let handle = Builder::new(INITIAL_PRIORITY)
.stack_size(STACK_SIZE)
.name(format!("cairo-ls:worker:{i}"))
.spawn({
let job_receiver: Receiver<Job> = job_receiver.clone();
let job_receiver: channel::Receiver<Job> = job_receiver.clone();
move || {
let mut current_priority = INITIAL_PRIORITY;
for job in job_receiver {
Expand Down

0 comments on commit 4a75102

Please sign in to comment.