How to allocate thread local storage?

前端 未结 9 1315
夕颜
夕颜 2020-12-07 10:40

I have a variable in my function that is static, but I would like it to be static on a per thread basis.

How can I allocate the memory for my C++ class such that eac

9条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-07 11:23

    Just a side note... MSVC++ supports declspec(thread) from VSC++2005

    #if (_MSC_VER >= 1400)
      #ifndef thread_local     
        #define thread_local __declspec(thread)
      #endif
    #endif
    

    Main problem is(which is solved in boost::thread_specific_ptr) variables marked with it can't contain ctor or dtor.

提交回复
热议问题