xiaoya2...@gmail.com wrote: > Greetings LMDB Community, > > I am delving into the thread-safety aspects of LMDB, specifically regarding > the use of readonly cursors across multiple threads. With the MDB_NOTLS flag > enabled, which disables thread-local storage, my understanding is that > readonly transactions may be shared between threads, provided there is proper > synchronization to prevent concurrent access. > > Building upon this, I seek clarity on the following: Can multiple threads > safely access a single readonly cursor derived from such a synchronized > readonly transaction when MDB_NOTLS is enabled? > > Upon reviewing the LMDB source code, I noticed that cursors are tied to > transactions (see mdb.c#L1335). This suggests that if threads can > synchronously share a transaction, they might also share a cursor associated > with it for data retrieval. > > Meanwhile, while looking at the LMDB document > (http://www.lmdb.tech/doc/group__mdb.html#gad7ea55da06b77513609efebd44b26920), > it says “Cursors may not span transactions”, which is a little confusing for > me. To be crystal transparent, does it mean that, even if MDB_NOTLS is set, a > cursor opened by a readonly transaction still has to stay with one single > thread for its entire lifetime, and cannot be used by another thread even at > a different time?
No that's not what it means. If it were to mean that, it would have said "cursors may not span threads". -- -- Howard Chu CTO, Symas Corp. http://www.symas.com Director, Highland Sun http://highlandsun.com/hyc/ Chief Architect, OpenLDAP http://www.openldap.org/project/