linux - pthread_once() 是否支持“链接”另一个 init_routine?
问题描述
是否从支持的 init_routine 中调用另一个 pthread_once(使用不同的 once_control 和 init_routine)?
例如,
static pthread_once_t gl_ctl_one = PTHREAD_ONCE_INIT;
static pthread_once_t gl_ctl_two = PTHREAD_ONCE_INIT;
int main (int argc, char *argv[])
{
pthread_once(&gl_ctl_one, rtn_one);
};
void rtn_one()
{
printf("rtn_one\n");
/**********************************************/
/* Call the second init if needed */
/**********************************************/
pthread_once(&gl_ctl_two, rtn_two);
return;
}
void rtn_two()
{
printf("rtn_two\n");
return;
}
我实际上是在尝试初始化两个不同的“.so”“包”,所以我需要有两个单独的初始化例程。(我不能把它们合二为一,可能涉及也可能不涉及多个进程和线程)。
rtn_one() 实际上在一个.so 中,而 rtn_two() 在另一个.so 中。
在http://pubs.opengroup.org/onlinepubs/9699919799/上查看 pthread_once 的文档让我有点困惑。他们提到“递归”是一个坏主意,但仅提及尝试使用相同的 once_control (我对他们的推理有点困惑):
“如果 init_routine 以相同的 one_control 递归调用 pthread_once(),则递归调用将不会调用指定的 init_routine,因此指定的 init_routine 将不会完成,因此对 pthread_once() 的递归调用将不会返回。”
就我而言,我使用的是 Centos 7.5 linux,它似乎可以工作(我不确定 pthread_once() 中的内部互斥锁是否会导致问题)。
但是,我不确定这是否是承诺的行为。
解决方案
推荐阅读
- c# - 如何以编程方式设置重用幻灯片窗格和打开文件打开对话框上的浏览按钮的路径,以便在 Powerpoint 中重用幻灯片
- javascript - 悬停在文本上以显示 ul 元素
- neo4j - Cosmos db 图中不支持来自 Tinkerpop 3 的哪些步骤/gremlin 查询
- primefaces - 如何使用 javascript/jquery 从 p:selectOneListBox 设置所选项目
- javascript - jQuery - 将变量作为选项传递
- angular - 角度路由:未捕获(承诺):错误:无法匹配任何路由
- c# - 如何将 LINQ 查询写入 sql IN
- python - 如何有效过滤熊猫数据框并返回熊猫系列?
- python - 围绕给定轴旋转任意平面会导致结果不一致
- laravel - 我想使用 if 语句显示 2 个数据