google / tensorstore

Library for reading and writing large multi-dimensional arrays.
https://google.github.io/tensorstore/
Other
1.32k stars 118 forks source link

Clarify in documentation if the C++ API is thread safe #159

Open mkitti opened 1 month ago

mkitti commented 1 month ago

Is the the C++ API thread safe? Are there any considerations when calling tensorstore from multiple threads?

laramiel commented 1 month ago

The C++ api surface is quite large, however, generally speaking, tensorstore is designed to be thread-compatible at the c++ object level. So, unless otherwise marked, it's best to partition or guard tensorstore object uses when working with threads.

See, for example, the Abseil blog post on C++ types: https://abseil.io/blog/20180531-regular-types

jbms commented 1 month ago

All const methods are thread-safe, non-const methods are not thread safe.

All const uses of a TensorStore object (which is almost all uses) are thread-safe, for example.

Most objects in TensorStore are internally reference counted and use thread-safe copy-on-write internally where needed.