Transaction with Mutex?

I’m newbie with cblite (i use cblite C v3.0.2)

I read a doc and know, the CBLDatabase_BeginTransaction & CBLDatabase_EndTransaction is support to Multiple writes are much faster when grouped in a transaction
so if many thread have write to db, should combine Transaction & Mutex? (the data is have different type at each thread)

CBLDatabase_BeginTransaction only need call before CBLDatabase_SaveDocument and CBLDatabase_EndTransaction later call right ?

I would think that it’s simpler to have each thread manage its own transaction instead of having them to contribute to the same transaction. Each thread could have its own database to own the transaction.

CBLDatabase_BeginTransaction only need call before CBLDatabase_SaveDocument and CBLDatabase_EndTransaction later call right

That is correct.

I’m not quite sure what you’re asking.

If you’re using a single CBLDatabase instance on multiple threads, then you will probably want to acquire a mutex before beginning a transaction and release it after committing. Otherwise writes by other threads could get mixed in.

Unless you have a whole lot of threads, it’s better to use a separate CBLDatabase object on each thread, because it avoids this problem – if you’re in a transaction and another thread calls CBLDatabase_BeginTransaction on a separate CBLDatabase, it will block until the current transaction ends. You also get better concurrency for reads this way.