snipsco / snips-nlu-rs

Snips NLU rust implementation
https://snips.ai
Other
340 stars 56 forks source link

Can one engine instance be used across mnany threads? #154

Closed allisterb closed 4 years ago

allisterb commented 4 years ago

I want to use the native snips_nlu_ffi library binary in a multi-threaded app. Is it safe to share one engine pointer across many threads and call functions like snips_nlu_engine_run_get_intents concurrently?

fredszaq commented 4 years ago

@allisterb the engine is internally protected by a mutex, so you can share it across threads and use it concurently without any problems

adrienball commented 4 years ago

@fredszaq The underlying SnipsNluEngine struct is Send + Sync so I think we could get rid of this mutex (there are other mutexes at a lower level in the implementation). This would improve concurrency.

allisterb commented 4 years ago

Awesome, thanks a lot.