3 ms·
So, I guess I fall in the middle. I have no issues with lock_guard. Also, it will unlock on destruction, which is not much of a problem. And having this sort o
by gpderetta 6y ago
So, I guess I fall in the middle.
I have no issues with lock_guard. Also, it will unlock on destruction, which is not much of a problem. And having this sort of side effect at end of scope is consistent with languages having synchronized or atomic blocks.
I would also not have much of a problem with a join_guard that joins one or more thread on destruction.
I am a fan of RAII and both lock_guard and join_guard have a single job and if you use them it is pretty obvious what you want, you can opt in on them and you can delegate the job by passing them around.
My issue is with more complex objects blocking on destruction when it is not their primary purpose.