我有这样的一个子线程执行,我想给他一个名字,到时候方便查看线程ID对应的线程名,这样我就知道这个线程是干什么的了
环境Linux
void MongoDBManager::ClientThread(const string& uri)
{
m_mongodb_writer = mp_create_mongo_proxy();
if (!m_mongodb_writer->mongodb_init(uri.c_str(), MONGO_POOL_SIZE)) {
LOG(ERROR)("create mongo writer thread failed");
return;
}
while (true) {
if (m_stop == true && m_queue.size_approx() == 0) {
break;
}
mongo_task* task;
if (m_queue.size_approx() == 0) {
Sleep(10);
continue;
}
if (m_queue.wait_dequeue_timed(task, std::chrono::milliseconds(1000)) == false)
{
LOG(ERROR)("mongo write queue get task timeout, size(%d) ", m_queue.size_approx());
continue;
}
task->handle(m_mongodb_writer);
delete task;
task = NULL;
Sleep(1);
}
if (m_mongodb_writer == nullptr) { return; }
m_mongodb_writer->mongodb_stop();
mp_delete_mongo_proxy(m_mongodb_writer);
LOG(INFO)("mongodb client release writer");
return;
}