c++ - boost::thread_specific_ptr slows drastically relative to simple TlsGetValue and TlsSetValue -


i had small class called wcthreadspecificprivatedata. implementation:

class wcthreadspecificprivatedata { public:     wcthreadspecificprivatedata();     ~wcthreadspecificprivatedata();      void* getdata();     void  setdata(void*);  protected:     uint32_t m_datakey; };  wcthreadspecificprivatedata::wcthreadspecificprivatedata():m_datakey(0) {     m_datakey = ::tlsalloc(); }  void* wcthreadspecificprivatedata::getdata() {     void* retval = 0;      if (0 != m_datakey)         retval = ::tlsgetvalue(m_datakey);     return retval; }  void  wcthreadspecificprivatedata::setdata(void* in_data) {     if (0 != m_datakey)         ::tlssetvalue(m_datakey, in_data); } 

i used store pointers thread specific struct called targetspecificdata. @ point decided use instead of class boost::thread_specific_ptr. works me, however, experience drastic performance drop. became more slower.

i checked boost implementation (for windows) , saw implemented tlsgetvalue , tlssetvalue calls, expect same behavior. can suggest caused such drop?

i can't give many ideas "what caused such drop", largely because don't show how use thread_specific_ptr.

also, consider using thread_local (c++11) compilers "roughly" support now. (there minor limitations, static initialization of non-trivial types). nothing cannot worked around lambda-initializer:

thread_local std::unique_ptr<my_thing> thing =           [] { return new std::unique_ptr<my_thing>(); }(); 

update in fact, there might reason: if creating many threads (and letting them run completion) there might more destructions (boost::thread_specific_ptr destructs contained entity @ exit of boost::thread)


Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -