-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SYNC is not implemented for ThreadPool #96
Comments
Hi Sorry this reply is so late. The reason we can not implement Sync is that the underlying channel does not implement it. Cheers, |
We should probably just put a |
One requirement currently is that this crate compiles with rust 1.9. |
Just as a small bump, I'm also in a situation where a |
As a workaround, if it's fine to lock/unlock the mutex for every use std::sync::{Arc, Mutex};
use threadpool::ThreadPool;
/// A Send + Sync thread pool.
#[derive(Debug, Clone)]
pub struct SyncThreadPool {
pool: Arc<Mutex<ThreadPool>>,
}
impl SyncThreadPool {
/// Create a new thread pool with the specified size.
pub fn new(num_threads: usize) -> Self {
Self {
pool: Arc::new(Mutex::new(ThreadPool::new(num_threads))),
}
}
/// Execute a job on the thread pool.
pub fn execute(&self, job: impl FnOnce() + Send + 'static) {
self.pool
.lock()
.expect("could not lock thread pool mutex")
.execute(job)
}
} This should have the same performance characteristics as if a mutex were used internally. |
I am trying to create a threadpool as static. So that I dont have to pass this variable across multiple functions.
I get the following error
| |_^
std::sync::mpsc::Sender<std::boxed::Box<(dyn threadpool::FnBox + std::marker::Send + 'static)>>cannot be shared between threads safely
|
The text was updated successfully, but these errors were encountered: