-
Notifications
You must be signed in to change notification settings - Fork 56
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
Can EGraph be Sync + Send? #516
Comments
I'm not super familiar with Rust concurrency, but the following code gives me many different error messages (that are not related to const _: () = {
fn assert_send<T: Send>() {}
fn assert_sync<T: Sync>() {}
fn assert_all() {
assert_send::<EGraph>();
assert_sync::<EGraph>();
}
}; |
Also, what is your use case? We can (maybe?) make it |
I would like to use EGraph with lazy_static lazy_static::lazy_static! {
pub static ref RT: std::sync::Mutex<EGraph> = std::sync::Mutex::new(EGraph::default());
} you are right, there are numbers of errors, not only the Parser.
|
Currently the union-find can not be easily made thread safe due to it's use of interior mutability. We are working on a new backend for egglog that will support parallel access. In the meantime, if you want a global mutable e-graph, I suggest just passing it around. If you require interior mutability, you can use |
Actually, I'm able to make the EGraph implement the Interior mutability could be an issue, but not in this case I think. For example, UnionFind::find takes an immutable self reference but updates its entries, so if two immutable references to the EGraph concurrently call UnionFind::find, this may cause a race condition. But in the case of Mutex, this won't happen because only one reference (immutable or mutable) can be obtained at a time. In fact, wrapping the E-graph inside a
|
Thanks Yihong! I guess checking the |
Currently EGraph not Sync+Send due to
Arc<dyn Macro<T>>
not Sync+Send. Can we makeParser
Sync+Send?The text was updated successfully, but these errors were encountered: