我有一个场景如下,无法关闭图书馆
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;
}
我从指定了 -fno-unique-symbol 的 cpp 文件中创建了一个库,这样它就不会保留符号。
主要代码
#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
有人可以解释阻止库句柄的原因并告诉我如何调整代码以便我可以关闭库