libxml2.so Init/CleanupParser 多线程线程的用法
libxml2.so Init/CleanupParser usage for multiple processes with threads
我正在使用 libxml2 作为 共享库 来自 上不同的并行 运行ning 进程arm/linux环境。官方示例是一次性流程,其中 InitParser()
and CleanupParser()
的处理很简单。
在多个进程使用 libxml2 的设置中,我不确定如何使用它。
proc1 -thread1-> work -> libxml2.so -> ...
-thread2-> work -> ...
-thread3-> work -> work -> libxml2.so -> work -> ...
proc2 -thread1-> wrapper.so -> libxml2.so -> work -> ...
-thread2-> work -> ...
-thread3-> wrapper.so -> libxml2.so -> ...
问题
作为一个嵌入式设备,进程运行正常'forever',所以我不能承受任何内存泄漏。 (我用unittest+valgrind和live-运行+memory monitor测试代码)
InitParser()
不是可重入的,所以据我了解 InitParser()
=> ... => CleanupParser()
在线程级别上不行吗? (例如 proc1::thr1 与 proc1::thr3)
- 这就是为什么我正在考虑流程级别的管理。
但是 proc1
中的 CleanupParser()
调用会与 proc2's
libxml2 调用交互吗?
(它是 "tunneled-through" 共享库吗?)
InitParser()
Initialization function for the XML parser. This is not reentrant. Call once before processing in case of use in multithreaded programs
CleanupParser()
it cleans up memory allocated by the library itself. It is a cleanup
function for the XML library. It tries to reclaim all related global
memory allocated for the library processing. It doesn't deallocate any
document related memory. One should call xmlCleanupParser() only when
the process has finished using the library and all XML/HTML documents
built with it. See also xmlInitParser() which has the opposite
function of preparing the library for operations. WARNING: if your
application is multithreaded or has plugin support calling this may
crash the application if another thread or a plugin is still using
libxml2
我想,这个问题揭示了我对共享库内部工作的有限了解...感谢您的帮助!
xmlInitParser
不是线程安全的。最好在生成其他线程之前从主线程调用此函数一次,例如,在 main
.
的开头
如果进程的任何线程之后调用任何其他 libxml2 函数,则绝不能调用 xmlCleanupParser
。所以 xmlInitParser() ... xmlCleanupParser()
在线程级别上是不行的。您通常根本不需要调用 xmlCleanupParser
,但在使用 valgrind 或 ASan 等工具检查内存泄漏时,您需要它来避免误报。在这种情况下,最好在进程退出之前调用它,例如在 main
.
的末尾
我正在使用 libxml2 作为 共享库 来自 上不同的并行 运行ning 进程arm/linux环境。官方示例是一次性流程,其中 InitParser()
and CleanupParser()
的处理很简单。
在多个进程使用 libxml2 的设置中,我不确定如何使用它。
proc1 -thread1-> work -> libxml2.so -> ...
-thread2-> work -> ...
-thread3-> work -> work -> libxml2.so -> work -> ...
proc2 -thread1-> wrapper.so -> libxml2.so -> work -> ...
-thread2-> work -> ...
-thread3-> wrapper.so -> libxml2.so -> ...
问题
作为一个嵌入式设备,进程运行正常'forever',所以我不能承受任何内存泄漏。 (我用unittest+valgrind和live-运行+memory monitor测试代码)
InitParser()
不是可重入的,所以据我了解InitParser()
=> ... =>CleanupParser()
在线程级别上不行吗? (例如 proc1::thr1 与 proc1::thr3)- 这就是为什么我正在考虑流程级别的管理。
但是proc1
中的CleanupParser()
调用会与proc2's
libxml2 调用交互吗?
(它是 "tunneled-through" 共享库吗?)
- 这就是为什么我正在考虑流程级别的管理。
InitParser()
Initialization function for the XML parser. This is not reentrant. Call once before processing in case of use in multithreaded programs
CleanupParser()
it cleans up memory allocated by the library itself. It is a cleanup function for the XML library. It tries to reclaim all related global memory allocated for the library processing. It doesn't deallocate any document related memory. One should call xmlCleanupParser() only when the process has finished using the library and all XML/HTML documents built with it. See also xmlInitParser() which has the opposite function of preparing the library for operations. WARNING: if your application is multithreaded or has plugin support calling this may crash the application if another thread or a plugin is still using libxml2
我想,这个问题揭示了我对共享库内部工作的有限了解...感谢您的帮助!
xmlInitParser
不是线程安全的。最好在生成其他线程之前从主线程调用此函数一次,例如,在 main
.
xmlCleanupParser
。所以 xmlInitParser() ... xmlCleanupParser()
在线程级别上是不行的。您通常根本不需要调用 xmlCleanupParser
,但在使用 valgrind 或 ASan 等工具检查内存泄漏时,您需要它来避免误报。在这种情况下,最好在进程退出之前调用它,例如在 main
.