DBMgr* ConnPool::GetConn() { pthread_t id = pthread_self(); //unsigned long id = pthread_self(); ConnMap::iterator it = conn_map_.find(id); if ( it == conn_map_.end()) { //if (!conn_map_[id]) { DBMgr* dbmgr = new DBMgr(); dbmgr->Init(ip_, port_, name_, user_, password_); std::pair<map<pthread_t,DBMgr*>::iterator, bool > ret = //std::pair<map<unsigned long ,DBMgr*>::iterator, bool > ret = conn_map_.insert(make_pair<pthread_t, DBMgr*>(id, dbmgr)); //conn_map_.insert(make_pair<unsigned long, DBMgr*>(id, dbmgr)); if (!ret.second) { printf("insert err\n"); } //} } return conn_map_[id]; }
发现之前只要用到 conn_map_[id]这样的用数组索引作为下标的取操作,再插入的时候就会出问题....
具体什么原因可能要看代码才知道了,,,
先记下来,以作备忘.