dbTalk Databases Forums  

Q: how should a multi-thread program open a db

comp.databases.berkeley-db comp.databases.berkeley-db


Discuss Q: how should a multi-thread program open a db in the comp.databases.berkeley-db forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Malcolm Dew-Jones
 
Posts: n/a

Default Q: how should a multi-thread program open a db - 12-12-2005 , 10:55 PM







I have a multi-threading program, a milter actually. Each thread needs to
read values from a db file.

Does each thread need to open the db file itself, or can all the threads
share the same handle to read the data? The db file is opened with the
DB_THREAD flag.



I checked some earlier work of mine and the milter opens the db file just
once at startup, and then all the threads used the same handle. That
appeared to work, but I am wondering now if it was a happy coincidence.

/* note the real code checks for errors */

DB *dbp = (DB*)calloc(1,sizeof(DB));
db_create( &dbp, NULL, 0);

flags=0;
flags |= DB_THREAD;
/* DBTXN comes from a sendmail header */
dbp->open(dbp, DBTXN dbfilename, NULL, DB_HASH, flags , 0444);


That single "dbp" handle is then used by all the threads for the db get's.
Is that a problem? Should each thread create and open the db file itself
(i.e. have it's own handle for the get() ? )


Reply With Quote
  #2  
Old   
Michael Cahill
 
Posts: n/a

Default Re: Q: how should a multi-thread program open a db - 12-13-2005 , 04:53 AM






Quote:
Does each thread need to open the db file itself, or can all the threads
share the same handle to read the data? The db file is opened with the
DB_THREAD flag.
That's what the DB_THREAD flag is for: when that flag is specified,
multiple threads can share a single handle.

Regards,
Michael.



Reply With Quote
  #3  
Old   
Michael Cahill
 
Posts: n/a

Default Re: Q: how should a multi-thread program open a db - 12-13-2005 , 04:53 AM



Quote:
Does each thread need to open the db file itself, or can all the threads
share the same handle to read the data? The db file is opened with the
DB_THREAD flag.
That's what the DB_THREAD flag is for: when that flag is specified,
multiple threads can share a single handle.

Regards,
Michael.



Reply With Quote
  #4  
Old   
Malcolm Dew-Jones
 
Posts: n/a

Default Re: Q: how should a multi-thread program open a db - 12-13-2005 , 06:27 PM



Michael Cahill (mjc (AT) sleepycat (DOT) com) wrote:
: > Does each thread need to open the db file itself, or can all the threads
: > share the same handle to read the data? The db file is opened with the
: > DB_THREAD flag.

: That's what the DB_THREAD flag is for: when that flag is specified,
: multiple threads can share a single handle.

That's what I thought, thanks, I just wanted another opinion to
be sure I wasn't out to lunch.


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.