문제

Is is possible in Boost threading to do something like this:

std::string key;
MyClass value;    
myThread->setData(key, value);    
MyClass retrievedValue = myThread->getData(key);

setData and getData are only imaginary methods to explain my need.


EDIT : I got the necessary answer by @SLaks. But for clarification : the purpose of the question was not "a method by method" equivalent, but it was a global equivalent by which we can set somewhere in the thread by a way something that we can get it somewhere else it by a way in the same thread... :)

Thank you!

도움이 되었습니까?

해결책

You're looking for thread-local storage.

Use boost:thread_specific_ptr.

다른 팁

Not as such, no.

It is possible though, to write your own thread class (implemented in terms of std::thread or boost::thread or something else), that also holds a map of values (besides the thread instance), and that does what you are asking.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top