Skip to main content
1 of 4
David
  • 1k
  • 6
  • 10

Problems with add:

  • the while(true) is useless
  • you want to notify_one, not notify_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& and T&& (the latter would std::forward. This would be optimal in all cases.
  • you can use lock_guard instead of unique_lock and either let the lock cover the notify_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.

David
  • 1k
  • 6
  • 10