Couchbase Lite .NET threading on Xamarin iOS

#1

There is a section in the documentation that specifies that CouchbaseLite-iOS is not thread-safe and recommend to do things like “not use sharedInstance”. Does this apply to the CouchbaseLite.NET library when used in a Xamarin iOS app? Should I use the Manager.sharedInstance or create a new instance with each access? Should database operations always be on the main thread or background thread?

http://developer.couchbase.com/documentation/mobile/1.2/develop/guides/couchbase-lite/native-api/database/index.html

The Objective-C implementation follows the typical behavior of Cocoa classes: the classes are not themselves thread-safe, so the app is responsible for calling them safely. In addition, some of the classes post NSNotifications and need to know what runloop or dispatch queue to deliver the notifications on. Therefore, each thread or dispatch queue that you use Couchbase Lite on should have its own set of Couchbase Lite objects

If your app uses Couchbase Lite on multiple threads, then on each thread (or dispatch queue) it must:

Create a new CBLManager instance. If you use multiple threads, do not use the sharedInstance.
Use only objects (Databases, Documents, …) acquired from its Manager.
Not pass any Couchbase Lite objects to code running on any other thread/queue.

#2

No, the concurrency support is based on which CBL implementation you’re using, not the underlying OS. The .NET implementation is thread-safe.

#3

In fact, the opposite is dangerous. You should not create more than one manager instance for any given directory or all the thread safety assumptions are false.