| anthonymoss78 (1) | |
|
Hi, I am trying to write a program that holds a particular unique value to each thread and ability to access this unique value at any time. I have been using the boost::thread_specific_ptr : but not having much luck.. below is a snapshot: class LogId { public: LogId(string id) : id_ (id) { } ~LogId() { } string getId() { return id_; } private: string id_; }; static boost::thread_specific_ptr<LogId> ptrId_; inline void SetTrLogId(const string& id) { if (ptrId_.get() == NULL) { ptrId_.reset( new LogId(id) ); } } inline string getTrLogId() { if (ptrId_.get() == NULL) { return string(""); } return ptrId_.get()->getId(); } And when I call SetTrLogId(..) to set it up .. and then call getTrLogId() in the same thread (I have compared pid values so I know the same thread).. the ptrId_.get() always returns null. Can anyone assist please thanks | |
|
|
|
| computerquip (1997) | |
|
http://codepad.org/8ABE1psM - Much more readable. Use [Code] tags please. I'm unsure of you're goal or what you're wanting. I don't believe that you've used thread_specific_ptr correctly (specifically that its a global), I also don't think there's any real purpose in your wrapper functions. | |
|
|
|