如果访问静态类成员例如调用boost :: this_fiber :: get_id,dlclose不会释放库句柄

问题描述

我的情况如下,无法关闭图书馆

liba.so

  #include <iostream>
  #include <boost/fiber/all.hpp>
  using namespace std;

  int func1(int)
  {
    cout << "this fiber id " << boost::this_fiber::get_id() << endl; // if this line is commented out then the problem resolved.
    cout << "It is a func1" << endl;
    return 1;
  }

我从cpp文件中创建了一个库,其中指定了-fno-unique-symbol,这样它就不应保留该符号。

主要代码

#include <stdio.h>
#include <stdlib.h>
#include <dlfcn.h>
#include <sys/types.h>
using namespace std;
int fun(string & flName)  {
  void *handle;
  typedef int (*fn)(int);
  fn fn1;
  handle = dlopen(flName.c_str(),RTLD_LOCAL|RTLD_LAZY);
  fn1 = (fn)dlsym(handle,"_Z5func1I");
  (*fn1)(2);
  cout << "handle :" << handle << endl;
  int ext_code = dlclose(handle);
  printf ("end exit code %d\n",ext_code);
}

int main(void)    {
  std::string fileName("dirpath/liba.so");
   fun(fileName);
   fun(fileName);
   fun(fileName);
   return 0;
}

输出,当this_fiber被注释掉

  • 手柄:0x234567
  • 结束退出代码0
  • 句柄:0x345678
  • 结束退出代码0
  • 手柄:0x456789
  • 结束退出代码0

-----但是当this_fiber :: get_id()处于活动状态时,

  • 手柄:0x234567
  • 结束退出代码0
  • 句柄:0x234567
  • 结束退出代码0
  • 手柄:0x234567
  • 结束退出代码0

有人可以解释一下阻止库句柄的原因,并告诉我如何调整代码,以便我可以关闭库

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...