threadsafe talloc
tridge at samba.org
tridge at samba.org
Sun Feb 7 16:56:22 MST 2010
Hi Volker and Simo,
As you know, I'm not a big fan of threads, but if you do want to make
talloc thread safe, then I think it should be done like this:
- all the thread stuff should be #ifdef'd, so there is no performance
penalty when not needed
- as Simo suggests, add a thread id to the talloc_chunk structure,
but don't deny operations that are between threads, instead just
optimise for the case where operations are within a thread. The
simplest way to do this is to have a global array of mutexes
indexed by a hash of the thread-id. So when you lock a context you
get the mutex corresponding to the hash of the threadid in the
context. This will be zero-contention for the common case that the
same thread that is manipulating the context also created it. Have
a separate mutex for the null_context and autofree_context. When
you create a new context, set its threadid to the current threads
thread ID.
- add a TALLOC_FLAG_THREADED flag to the flags field of
talloc_chunk. This will be used to detect the use of mixed
threaded/non-threaded operation, which should abort
- make the changes as non-intrusive as possible. That means use cpp
macros and helper functions to hide the gory details of the locking
from the main code. The talloc code is complex enough already
without having complex mutex code spread throughout it.
The hardest bit will be the lock ordering. That will require some
careful thought to ensure that you can't deadlock.
Cheers, Tridge
More information about the samba-technical
mailing list