talloc null context thread safe ?
Rémi
turboult at easynet.fr
Wed Nov 8 14:55:25 GMT 2006
Rémi <remi.turboult at m4x.org> a écrit :
>> 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" ?
>
I just realized that the "talloc_autofree_context" is also a global so
this context as well shouldn't be shared between threads without
precautions. Here is my updated proposal to add in "talloc_guide.txt" :
"
Multi-threading
---------------
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 synchronize 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 synchronization ;
- the context returned by talloc_autofree_context() is also global so
shouldn't be used by several threads simultaneously without
synchronization.
"
Regards,
Rémi
More information about the samba-technical
mailing list