c++ - How to release heap memory of thread local storage -
i have construction used thread local storage this:
namespace { typedef boost::unordered_map< std::string, std::vector<xxx> > yyy; boost::thread_specific_ptr<yyy> cache; void initcache() { //the first time called current thread. if (!cache.get()){ cache.reset(new yyy()); } } void clearcache() { if (cache.get()){ cache.reset(); } } }
and class object have been created main thread
:
class { public: void f() { initcache(); //and example: insertintocache(); } ~a(){ clearcache();// <-- does/can ?? } }
multiple threads can access object(s) of a
stored, example, in global container. each of these threads need phone call a::f()
time time. create own re-create of cache
on heap
1 time , , bring together when done jobs.
so question : going clean-up threads' memory? , how? give thanks you
there's no reason phone call clearcache()
.
once thread exits or thread_specific_ptr
goes out of scope, cleanup function invoked. if don't pass cleanup function thread_specific_ptr
's constructor, utilize delete
.
c++ multithreading boost-thread thread-local thread-local-storage
No comments:
Post a Comment