klauspost / reedsolomon

Reed-Solomon Erasure Coding in Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is encoder thread-safe?

1a1a11a opened this issue · comments

Can I use the same encoder in multiple goroutines?

The core struct (type reedSolomon struct) is largely stateless, except for the field tree of type inversionTree, which is a specialised cache for temporary storage of matrices used for reconstruction.

inversionTree is protected by a mutex.

So to the best of my knowledge, yes it is safe to use it in multiple goroutines for all scenarios.

All good.

The same architecture is implemented in a Rust port of this library, and Rust would complain if it's not thread-safe when you use it in a multi-thread scenario. So overall I believe it is thread-safe.

Yes, it is, but checking with the race detector is of course always recommended - if nothing more then to check your side of the code.