I'm writing a simple multithreaded md5 hash cracker using a task farm, except i keep getting read access violations seemingly at random. heres the function the threads run:
void Farm::run(){
std::vector<thread> workers;
std::mutex queuemtx;
int maxthreads = thread::hardware_concurrency();
for (int i = 0; i < 1; i++) {
workers.emplace_back(thread([&]() {
hashcrackertask* temp;
queuemtx.lock();
while (!taskqueue.empty()) {
temp = taskqueue.front();
queuemtx.unlock();
temp->run();
taskqueue.pop();
queuemtx.lock();
}
queuemtx.unlock();
}));
}
for_each(workers.begin(), workers.end(), [](thread& t) {
t.join();
});
}
and the section of code filling the queue:
thread readfileTH([&]() {
//loops through every line in the file
while (std::getline(rockyou, str)) {
while (f.queue_len() >= 20000) {
std::this_thread::sleep_for(std::chrono::milliseconds(5));
}
if (str.size() > 0) {
f.add_task(new hashcrackertask(str, passhash));
}
}
});
Any clue what could be throwing the error?