如何检查 libxml2 是否已初始化
How to check if libxml2 is initialized
根据this document about multithreading, it is mandatory to call xmlInitParser()
before using the library concurrently. Here's the problem. I coded a library(not an executable) using libxml2 and it should guarantee concurrency. So I decided to call the init function on my library's init function. However, the document所说的函数是不可重入的。因此,如果其他库或链接我的库的程序预先调用该函数,可能会出现问题。
我找不到检查解析器(或者我应该说是 libxml2)是否已初始化的函数或方法。我应该怎么办?无论如何调用函数并希望最好?在我 post this but that doesn't really tally.
之后,我将测试函数是否可重入
为了澄清,总结一下:
xmlInitParser()
实际上是可重入的吗?
- 有什么方法可以检查 libxml2 是否已初始化?
- (OR) 如何在另一个软件也可以同时使用的前提下安全地并发使用 libxml2。
查看源代码(取自here)后,似乎可以多次调用该函数:
static int xmlParserInitialized = 0;
void
xmlInitParser(void) {
if (xmlParserInitialized != 0)
return;
#ifdef LIBXML_THREAD_ENABLED
__xmlGlobalInitMutexLock();
if (xmlParserInitialized == 0) {
#endif
/* ... the actual initialization ... */
xmlParserInitialized = 1;
#ifdef LIBXML_THREAD_ENABLED
}
__xmlGlobalInitMutexUnlock();
#endif
}
您担心多个其他库同时调用 xmlInitParser()
。 System V ABI 意味着库被一个接一个地加载(参见 "Initialization and Termination Functions" 部分)。
[假设 none 的其他库创建线程(调用 xmlInitParser()
)] 这意味着您不必担心它。
如果你真的想安全起见,你应该 link 将 libxml 静态地放在你的库中,这样你就有了自己的私有副本,其他库无法干扰。
根据this document about multithreading, it is mandatory to call xmlInitParser()
before using the library concurrently. Here's the problem. I coded a library(not an executable) using libxml2 and it should guarantee concurrency. So I decided to call the init function on my library's init function. However, the document所说的函数是不可重入的。因此,如果其他库或链接我的库的程序预先调用该函数,可能会出现问题。
我找不到检查解析器(或者我应该说是 libxml2)是否已初始化的函数或方法。我应该怎么办?无论如何调用函数并希望最好?在我 post this but that doesn't really tally.
之后,我将测试函数是否可重入为了澄清,总结一下:
xmlInitParser()
实际上是可重入的吗?- 有什么方法可以检查 libxml2 是否已初始化?
- (OR) 如何在另一个软件也可以同时使用的前提下安全地并发使用 libxml2。
查看源代码(取自here)后,似乎可以多次调用该函数:
static int xmlParserInitialized = 0;
void
xmlInitParser(void) {
if (xmlParserInitialized != 0)
return;
#ifdef LIBXML_THREAD_ENABLED
__xmlGlobalInitMutexLock();
if (xmlParserInitialized == 0) {
#endif
/* ... the actual initialization ... */
xmlParserInitialized = 1;
#ifdef LIBXML_THREAD_ENABLED
}
__xmlGlobalInitMutexUnlock();
#endif
}
您担心多个其他库同时调用 xmlInitParser()
。 System V ABI 意味着库被一个接一个地加载(参见 "Initialization and Termination Functions" 部分)。
[假设 none 的其他库创建线程(调用 xmlInitParser()
)] 这意味着您不必担心它。
如果你真的想安全起见,你应该 link 将 libxml 静态地放在你的库中,这样你就有了自己的私有副本,其他库无法干扰。