Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug caused by thread_local variable? #180

Open
liuwenxin98 opened this issue Apr 24, 2023 · 0 comments
Open

Bug caused by thread_local variable? #180

liuwenxin98 opened this issue Apr 24, 2023 · 0 comments

Comments

@liuwenxin98
Copy link

liuwenxin98 commented Apr 24, 2023

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> 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 <thread>

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant