Skip to main content
3 of 4
deleted 60 characters in body
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::move. This would be optimal in all cases. (analogous to push_back in standard containers)
  • You may also want to add an emplace to complement the add() versions so you can construct T in-place at the top of the Buffer.
  • you can use lock_guard instead of unique_lock and scope it with {}s. I'd just say always prefer the lighter weight construct when a heavier weight one isn't strictly needed.
David
  • 1k
  • 6
  • 10