[Date Prev][Date Next] [Chronological] [Thread] [Top]

Re: Multiple threads and mdb_dbi_open



Harry B wrote:

Let me rephrase and see if I understand correctly.

1. If I have 10 threads (but only one database), then I would need to create
10 dbi handles to the same DB and then use them as required from each thread
making sure no two threads share the same DBI handle?

No. Re-read the documentation that you linked. It very clearly states that if you open the same DB multiple times you will get the same handle back, so why would you ever try to open it 10 times for 10 threads??

It also says very clearly that after the handle is persisted into the shared environment it may be used by other transactions.

2. Inside each thread, I would open a new transaction (as required for the
then relevant/appropriate read/write operation), but I would use a DBI handle
obtained in the main thread even though that DBI was created using a different
transaction handle that the one we are about to use for the current thread?


Thanks
--
Harry


On Thu, Sep 11, 2014 at 4:35 PM, Howard Chu <hyc@symas.com
<mailto:hyc@symas.com>> wrote:

    Harry B wrote:

        Hello,

        As per the documentation here
        http://symas.com/mdb/doc/__group__mdb.html#__gac08cad5b096925642ca359a6d6f0__562a
        <http://symas.com/mdb/doc/group__mdb.html#gac08cad5b096925642ca359a6d6f0562a>
        I see the following,

        "This function must not be called from multiple concurrent transactions. A
        transaction that uses this function must finish (either commit or abort)
        before any other transaction may use this function."

        This seems to imply that after one txn has begun on an environment, I
        cannot
        create another txn or dbi until the first one has finished - that
        doesn't seem
        to be right.

        If I have multi-threaded app, what is the expected sequence for
        creation of
        Environment, Transaction, and DBI handles?


    Before starting any other threads:
       Create the environment.
       Open a transaction.
       Open all DBI handles the app will need.
       Commit the transaction.

    After that use the DBI handles freely among any transactions/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/