On Tue, 2006-11-07 at 09:42 +1100, Andrew Bartlett wrote:
> On Mon, 2006-11-06 at 23:19 +0100, RÃmi wrote:
> > Hello,
> > I am using talloc in a project other than Samba : I hope this is the right
> > list for my question.
> I think so (that is, I know of no better place to ask).
> > I understand that talloc does not deal with threads, and in fact, it is
> > thread
> > safe, as long as each thread uses different memory contexts. If two threads
> > uses the same context then they need to synchronise in order to be safe.
> > Am I correct ?
> > If so, my concern is with the allocation of "top-level" contexts i.e. when
> > using a NULL parent. When using the "talloc_enable_leak_report", I
> > understand
> > that the NULL context is in fact a hidden "null context" global variable,
> > so
> > allocating anything from the NULL context (e.g. tmp_ctx = talloc_new
> > (NULL))
> > is no longer thread safe. Am I missing something, or may be this is obvious
> > ?
> > So in multi-thread environement, I should never use a NULL context as a
> > parent
> > (may be instead define my own per-thread null-context).
> In short, you should never use the NULL context, particularly in your
Yeah using the NULL context kind of defeats the purpose of the talloc
hierarchy, but the top level context is going to be a NULL one anyway.
I'd say that the best thing is to probably change talloc to save the pid
and create a "null context list" indexed by pid so that you can have a
per-thread top-level context when talloc_enable_leak_report() is in use.
Samba Team GPL Compliance Officer