tdb API issues

tridge at tridge at
Wed Apr 1 23:33:50 GMT 2009

Hi Howard,

The error code isn't the only place where tdb doesn't mix well with
threads. Things like tdb_traverse() involve state in the tdb context,
and all the tdb_lock primitives would affect the whole process, not
just a thread.

The same goes for the transaction code. For a threaded environment,
you'd like it if it worked so that when thread1 was in a transaction,
that thread2 would be blocked in writes, and reads would see the
pre-transaction data (this is what happens with two processes in tdb).

If you can arrange it so that each thread has its own tdb context then
life will be much simpler. That gives you a separate ecode per thread
as well. The problem is that you'll probably need to use some other
locking mechanism than fcntl locks, so you'll need to offer a hook
that abstracts away the locking primitives. Trying to make this work
so that tdb operations can also be performed safely by other processes
on the same tdb that is being used by your threaded task will be
interesting (I think its possible, just a bit tricky).

tdb and threads certainly isn't easy :-)

Cheers, Tridge

More information about the samba-technical mailing list