Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds 'Send' to glucose, so it can be sent between threads, and add a test. This could probably be added to other solvers too, I'd have to quickly skim their code to check for thread-local stuff, but I don't expect to find any.
Adding 'Send' lets you put a solver in a Mutex and pass it between threads. I want to do this as I want to make a threadpool of solvers, and this makes things much easier when I do that :)
if you are generally happy with this, I'm happy to go and add similar code to other solvers (I only added it to the solver I'm currently using).
(I'll write some more here about my understanding of multi-threading in Rust, just in case you haven't done much multithreading in Rust. If you have, you can skip this :) )
There are two concepts in Rust used in multi-threading:
Send: It's safe to send this between threads
Sync: It's safe to const-access this from two threads
I'm confident that solvers are Send -- in C++ it is fine to take a glucose solver, pass it to another thread, and solve on that other thread. The only reason this wouldn't work is if there were any thread-local variables.
It might be fine to be Sync, but that's much trickier, it would involve carefully check if all the methods we treat as 'const' (like get solution, get number of nodes, etc) don't modify any data-structures. Checking that would require a lot more care. However, I also don't think it's particularly useful anyway -- we definately can't use the same solver to solve in two threads at once, and I don't think being able to read the result from two threads would be particularly useful anyway.