capstone-rust / capstone-rs

high-level Capstone system bindings for Rust
217 stars 75 forks source link

Implement Send trait for multithreaded usage #71

Closed XVilka closed 5 years ago

XVilka commented 5 years ago

To be able to call like

pub static ref ARM_DISASSEMBLER: Mutex<Capstone> = 
    Mutex::new(Capstone::new().arm.expect("FAIL"));
tmfink commented 5 years ago

I don't think the Capstone struct will ever be Send or Sync because of how the struct is stored. The Capstone struct holds a csh which is essentially a pointer to an opaque C struct. Any way to make the it safe to share across threads (like an internal mutex) would increase the overhead for the single-threaded case.

If you want to disassemble in parallel, then I suggest you create a separate Capstone in each thread. You could create a function/closure that creates a Capstone like you want then use that function in each thread.

I should really have an multi-threaded example.