Um, yeah, I'm aware of that. That's the whole point of me suggesting that he use std::lock_guard instead of doing it manually. :p
Type: Posts; User: antred
Um, yeah, I'm aware of that. That's the whole point of me suggesting that he use std::lock_guard instead of doing it manually. :p
Hate to quote myself, but apparently I can no longer edit my post. Obviously I meant what happens if something throws an exception after you've locked the mutex but before you've unlocked it?
From your code sample above:
mtx.lock();
cur_best = best;
mtx.unlock();
Don't lock / unlock mutexes explicitly. It's prone to errors ... not so much in such a simple case, but what...