core: name codegen worker threads
This commit is contained in:
parent
06e9d90d57
commit
fb331c05b4
|
@ -273,11 +273,21 @@ impl WorkerRegistry {
|
||||||
let registry = registry.clone();
|
let registry = registry.clone();
|
||||||
let registry2 = registry.clone();
|
let registry2 = registry.clone();
|
||||||
let f = f.clone();
|
let f = f.clone();
|
||||||
let handle = thread::spawn(move || {
|
|
||||||
registry.worker_thread(generator.as_mut(), &f);
|
// Create a thread name for the worker,
|
||||||
});
|
// so when it panics, the error message would be
|
||||||
let handle = thread::spawn(move || {
|
// prettier than `thread '<unnamed>' panicked at <location>`
|
||||||
if let Err(e) = handle.join() {
|
let worker_thread_name =
|
||||||
|
format!("codegen-worker-{worker_id}", worker_id = generator.get_name());
|
||||||
|
let worker_handle = thread::Builder::new()
|
||||||
|
.name(worker_thread_name)
|
||||||
|
.spawn(move || {
|
||||||
|
registry.worker_thread(generator.as_mut(), &f);
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let collector_handle = thread::spawn(move || {
|
||||||
|
if let Err(e) = worker_handle.join() {
|
||||||
if let Some(e) = e.downcast_ref::<&'static str>() {
|
if let Some(e) = e.downcast_ref::<&'static str>() {
|
||||||
eprintln!("Got an error: {e}");
|
eprintln!("Got an error: {e}");
|
||||||
} else {
|
} else {
|
||||||
|
@ -287,7 +297,7 @@ impl WorkerRegistry {
|
||||||
registry2.wait_condvar.notify_all();
|
registry2.wait_condvar.notify_all();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
handles.push(handle);
|
handles.push(collector_handle);
|
||||||
}
|
}
|
||||||
(registry, handles)
|
(registry, handles)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue