Bug caused by thread_local variable?
- Dominant language
- C++
- Stars
- 5.3k
- Forks
- 570
- Avg merge
- 23h 43m
- Merged PRs (30d)
- 172
Description
The following error was encountered when using tcmalloc:
`external/com_google_tcmalloc/tcmalloc/sampler.cc:55] bytes_until_sample_ == 0 @ 0x7f6283a9d79b 0x7f6283a81d17 0x7f6283a81f99 0x7f6283a01dec 0x7f6283a03004 0x7f62839d581b 0x7f6283b28c30 0x7f62834ecd96
Aborted (core dumped)`
**A very simple method of reproduction**
Compiled using the bazel environment:
WORKSPACE:
`git_repository(
name = "com_google_tcmalloc",
commit = "bb24fb0a8be3a6ef52888d247097d05976b8918e",
remote = "https://github.com/google/tcmalloc.git",
)`
a.h:
`#include
thread_local int16_t var = -1;
`
b.h:
`#include "a.h"
class TestClass {
public:
TestClass();
~TestClass() {}
};`
b.cc:
`#include "b.h"
TestClass::TestClass() { var = 1; }
`
BUILD:
```
cc_library(
name = "var",
srcs = [
"a.h",
],
deps = [
"@com_google_tcmalloc//tcmalloc",
],
)
cc_binary(
name = "libtest.so",
srcs = [
"b.cc",
"b.h",
],
deps = [
":var",
],
linkshared = True,
)
```
test.cc:
```
#include
void test() {}
int main () {
auto t = std::thread(test);
t.join();
return 0;
}
```
use `bazel build :libtest.so` and `g++ -o test test.cc -pthread -L ./ -ltest` and './test' get this error
May I ask if this is a bug or if there is a problem with my usage? I hope to receive your help.
Sincerely!
Contributor guide
Assessment
This issue has not been assessed yet.