यह नीचे मेरे टेस्ट कोड में थ्रेडसेफ जैसा लगता है। क्या मैं मल्टीथ्रेड प्रोग्राम में Poco::Logger
का उपयोग कर सकता हूं?क्या पॉको :: लॉगर थ्रेडसेफ है?
static Poco::Logger *pLogger;
class MyRunnable : public Poco::Runnable {
private:
std::string _name;
Poco::Random _rnd;
public:
void setName(std::string name) {
_name = name;
}
void run() {
for (int i=0; i<200; i++) {
pLogger->information("info from: " + _name);
_rnd.seed(_rnd.next(65532) * _name.size());
Poco::Thread::sleep(_rnd.next(13) + 1);
}
}
};
यहाँ परीक्षण मुख्य है:
int
main (int argc, char *argv[])
{
Poco::Thread thr1, thr2, thr3;
MyRunnable *pMyR1 = new MyRunnable(),
*pMyR2 = new MyRunnable(),
*pMyR3 = new MyRunnable();
pMyR1->setName("r1");
pMyR2->setName("ra2");
pMyR3->setName("runable3");
Poco::FormattingChannel *pFCFile = new Poco::FormattingChannel(new Poco::PatternFormatter("%Y-%m-%d %H:%M:%S.%c %N[%P]:%s: %q:%t"));
pFCFile->setChannel(new Poco::FileChannel("test.log"));
pFCFile->open();
pLogger = &(Poco::Logger::create("FileLogger", pFCFile, Poco::Message::PRIO_INFORMATION));
thr1.start(*pMyR1);
thr2.start(*pMyR2);
thr3.start(*pMyR3);
std::cout << "starting..." << std::endl;
thr1.join();
thr2.join();
thr3.join();
std::cout << "end." << std::endl;
return EXIT_SUCCESS;
} /* ---------- end of function main ---------- */
[यह पृष्ठ] (http://www.appinf.com/docs/poco/Poco.Logger.html) केवल इतना कहता है कि 'unsafeGet' थ्रेड सुरक्षित नहीं है, इसलिए मुझे लगता है कि बाकी हैं। – chris
आम तौर पर, जब तक स्पष्ट रूप से निर्दिष्ट नहीं किया जाता है, आपको हमेशा कार्यक्षमता पर विचार करना चाहिए क्योंकि _not_ थ्रेड सुरक्षित है। –