-
Notifications
You must be signed in to change notification settings - Fork 35
Description
Currently, neither RandomXCache, RandomXDataset nor RandomXVM implement Send and Sync.
I think cache and dataset could implement both Send and Sync. For example, these structures are shared by VMs working in different threads in RandomX benchmarks: https://github.com/tevador/RandomX/blob/040f4500a6e79d54d84a668013a94507045e786f/src/tests/benchmark.cpp#L340-L365. It is essential to reuse cache and dataset to achieve high hashing rate using multiple threads.
I'm not 100% sure, but I think RandomXVM could also implement the Send trait. There doesn't seem anything that would make dropping a VM in a different thread unsound. It would allow putting it in a ThreadLocal to avoid recreating VMs every time a proof of work needs to be calculated. It would be useful for scenarios where many pows need to be verified in a short time.
Note: these traits are implemented by the archived moneromint/randomx4r:
- https://github.com/moneromint/randomx4r/blob/34df02f62426d799effd085eea4c806dc7d4a6d5/src/cache.rs#L38-L40
- https://github.com/moneromint/randomx4r/blob/34df02f62426d799effd085eea4c806dc7d4a6d5/src/dataset.rs#L78-L80
- https://github.com/moneromint/randomx4r/blob/34df02f62426d799effd085eea4c806dc7d4a6d5/src/vm.rs#L92
What do you think?