New issue
Advanced search Search tips

Issue 859128 link

Starred by 1 user

Issue metadata

Status: WontFix
Owner: ----
Closed: Jun 2018
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: ----
Pri: 3
Type: Bug



Sign in to add a comment

DEFINE_THREAD_SAFE_STATIC_LOCAL leaks objects per thread.

Project Member Reported by erikc...@chromium.org, Jun 29 2018

Issue description

Each time a thread accesses a DEFINE_THREAD_SAFE_STATIC_LOCAL, it will leak an object:
https://cs.chromium.org/chromium/src/third_party/blink/renderer/platform/wtf/std_lib_extras.h?type=cs&q=DEFINE_THREAD_SAFE_STATIC_LOCAL&sq=package:chromium&g=0&l=46

If a process creates an destroys threads dynamically [and the threads access the variable], this will cause an unbounded memory leak over time.

I suspect this will mostly affect the task scheduler [if it ever ends up making/destroy thread dynamically].

We should get rid of the macro. It's possible to accomplish the same behavior without leaking in a few lines of code:

e.g.
"""
base::ThreadLocalStorage::Slot& ShimStateTLS() {
  static base::NoDestructor<base::ThreadLocalStorage::Slot> shim_state_tls(
      &DestructShimState);
  return *shim_state_tls;
}

ShimState* GetShimState() {
  ShimState* state = static_cast<ShimState*>(ShimStateTLS().Get());

  if (!state) {
    state = new ShimState();
    ShimStateTLS().Set(state);
  }

  return state;
}
"""
 

Comment 1 by npm@chromium.org, Jun 29 2018

Cc: npm@chromium.org
Components: Blink>Internals>WTF
Let's expose base::ThreadLocalStorage::Slot in Blink then?
Status: WontFix (was: Untriaged)
Oh sorry, misread. DEFINE_THREAD_SAFE_STATIC_LOCAL doesn't have to do with TLS at all. 
Re. "I suspect this will mostly affect the task scheduler [if it ever ends up making/destroy thread dynamically]."

Task scheduler already *does* create/destroy threads dynamically.

Is DEFINE_THREAD_SAFE_STATIC_LOCAL ok after all (re. #2)?

Sign in to add a comment