void TransactionHandler::work() { //std::lock_guard<std::mutex> guard(m); //m.lock(); int i = 0; while (!mQueue.empty()) { //m.unlock(); //m.lock(); Transaction* t = mQueue.front(); mQueue.pop(); //m.unlock(); t->call(); //m1.lock(); //std::cout << std::this_thread::get_id() << ": " << i << std::endl; //m1.unlock(); i++; } //delete t; //m1.lock(); //std::cout << "I am " << std::this_thread::get_id() << " and I did " << i << " transactions. " << std::endl; //m1.unlock(); }
void TransactionHandler::callRandom(const unsigned int pTimes) { //std::lock_guard<std::mutex> locker(m); size_t s = mTransactions.size(); if (s > 0) { for (int i = 0; i < pTimes; i++) { //m.lock(); int random = RandomInt((int)mTransactions.size()); Transaction* t = new Transaction(mTransactions[random]); t->call(); //local variable delete t; //m.unlock(); //mTransactions[random].call(); } } }