1

Some codebases like skia define a static thread_local global variable. What is the point of having this as opposed to just a thread_local variable at a namespace scope?

// From: https://github.com/google/skia/blob/main/src/sksl/SkSLPool.cpp
namespace SkSL {
  static thread_local MemoryPool* sMemPool = nullptr;
  static MemoryPool* get_thread_local_memory_pool() {
      return sMemPool;
  }

  static void set_thread_local_memory_pool(MemoryPool* memPool) {
      sMemPool = memPool;
  }

}

What will happen if we remove static.

A. K.
  • 34,395
  • 15
  • 52
  • 89
  • 4
    `sMemPool` is a namespace scoped `thread_local` variable with internal linkage. So it can only be directly used by code in this compilation unit. Removing the `static` gives it external linkage. – Richard Critten Feb 04 '23 at 01:13

0 Answers0