Problems with add
:
- the while(true) is useless
- you want to
notify_one
, notnotify_all
because you've only added one thing, and so only one thread waiting to remove can remove it. - you should overload for two version which take
const T&
andT&&
(the latter wouldstd::forward
. This would be optimal in all cases. - you can use
lock_guard
instead ofunique_lock
and either let the lock cover thenotify_one
(cleanest code) or scope it with{}
s (most optimal code)
Lots of problems with the other functions too. I'll come back and comment more later if I get a chance.