Many of the Pia functions are not thread-safe. Calling them from multiple threads is not supported. Assume that a function is not thread-safe unless its API reference explicitly mentions otherwise. (Nintendo plans to add descriptions of functions that are thread-safe, as needed, to the documentation.) The application must provide exclusive control when calling Pia functions from multiple threads. Note that using a lock (or lock-like method) consumes CPU time.
Because Pia API functions sometimes call the NEX API, call all Pia functions from the same thread used to call NEX API member functions.
PiaTransport creates one thread for sending and one for receiving. Transfer processes that can block for a long period of time are handled in a dedicated transfers thread. The application will never block due to calls to the associated functions for sending or receiving data.
When using NEX, set the NEX thread mode to nn::nex::Core::ThreadModeUnsafeUser or nn::nex::Core::ThreadModeUnsafeTransportBuffer. If a different NEX thread mode is set, the Pia API may return an error or stop on an assertion failure.
For more efficient thread management, the Pia library uses one slot for nn::os::ThreadLocalStorage, starting from the call to nn::pia::common::Initialize(), and lasting until the call to nn::pia::common::Finalize().
Two slots are used in the debug and developer versions, and one slot is used in the release version. Be careful about the number of nn::os::ThreadLocalStorage slots used by the application.