talloc null context thread safe ?

Rémi turboult at easynet.fr
Tue Nov 7 08:50:33 GMT 2006

thanks for all your answers.

tridge at samba.org a écrit :
>  > 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.
> that's right. It doesn't affect Samba,

out of curiosity, why doesn't it affect Samba ? no threads, or not  
leak_reports ?

>  but it is something that should
> concern threaded programs.

may be for the time being it is possible to add a small paragraph in  
"talloc_guide.txt" ?
For example :


talloc itself does not deal with threads. It is thread-safe (assuming  
the underlying "malloc" is), 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.
In particular, when using talloc_enable_leak_report(), giving directly  
NULL as a parent context implicitly refers to a hidden "null context"  
global variable, so this should not be used in a multi-threaded  
environment without proper synchronisation.


More information about the samba-technical mailing list