These are my two classes:
class App {
public:
void run(){
std::vector < std::thread > th_list;
for(std::vector < Host * > ::iterator it = host_list.begin(); it != host_list.end(); it++){
th_list.push_back(std::thread(&App::th_getInfo, *this, *it, readFile(holder["cmdFile"])));
}
for(std::vector<std::thread>::iterator it = th_list.begin(); it != th_list.end(); it++){
it->join();
}
}
private:
void th_getInfo(Host * pc, std::string info){
std::string result;
if(pc->query(info, &result)){
holder.Push(pc->getIp(), result);
}
}
std::vector < Host * > host_list;
Holder holder;
};
class Holder {
public:
void Push(std::string ip, std::string data){
_m.lock();
std::pair <std::string, std::string> tmp(ip, data);
q.push(tmp);
std::cout << q.size() << std::endl;
_m.unlock();
}
inline std::string &operator[] (std::string j){ return config[j]; }
private:
std::map <std::string, std::string> config;
std::mutex _m;
std::queue < std::pair < std::string, std::string> > q;
}
So, my problem is that on every call of function Holder::Push q.size() equals 0 at start, and 1 at end of this function. Pushed object just disappears, but i don't call q.pop().