emilk / emilk/loguru

Thread local variable (thread_ec_ptr) prevents library to be unloaded

Open
#146 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
1.9k
Forks
280
Avg merge
7m
Merged PRs (30d)
4

Description

I have this scenario where I build an audio plugin on macOS as a dynamic library (`.dylib`). The host loads the plugin via `dlopen` and unloads it via `dlclose`.

My plugin uses `loguru` for logging.

After spending quite a bit of time figuring out an issue with the plugin I was able to track it down to this line https://github.com/emilk/loguru/blob/master/loguru.cpp#L1559

```
static LOGURU_THREAD_LOCAL ECPtr thread_ec_ptr = nullptr;
```

Simply compiling the plugin with loguru (even if not using it) causes the following issue: `dlclose` no longer unloads the plugin. Which means it is no longer possible to change the plugin on the fly and the entire host has to be brought down and back up again to get the new changes.

I believe the fact that the variable is tread local is what is causing the problem as proven by the fact that removing `LOGURU_THREAD_LOCAL` fixes the unloading/reloading issue.

Since I do not know or understand the internal workings of loguru, I was wondering if there are cases where this variable is not used and I can simply get rid of it. For example I know for a fact that my plugin will never ever run in a multi threaded environment so a thread local variable is most likely not useful.

Otherwise do you know of a fix (maybe a compiler flag?) that would fix this problem?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.