5 Multithreading in SODA for C Applications
SODA for C is designed for lockless multithreading in applications.
To achieve multithreading, just use separate handles in each thread of your SODA application. SODA handles are not designed to be shared between threads. In particular, they are not locked with mutexes to negotiate mutual exclusion among threads.
For example, to read or write to the same collection from multiple threads, obtain a separate collection handle in each thread using OCISodaCollOpen()
, and use each handle to perform read and write operations.
Only in the case of document handles can it sometimes make sense to share SODA handles among threads.
For example, one thread might create documents and put them into a queue, while worker threads dequeue the head document and insert it into a collection. Document handles could be shared among threads, here.
You don’t want multiple threads working on the same document at the same time, but a single document handle can be passed from one thread to another. It is your responsibility to provide application-level synchronization so that the document handle is not simultaneously accessed from different threads.