C++ optimizing multi-threaded application

Poby’s Home
Mar 4, 2021

--

Modern C++ has all the tools for thread optimization

https://www.youtube.com/watch?v=F6Ipn7gCOsY&ab_channel=CppCon

std::shared_lock

  • The class shared_lock is a general-purpose shared mutex ownership wrapper allowing deferred locking, timed locking, and transfer of lock ownership.
  • Locking a shared_lock locks the associated shared mutex in shared mode (to lock it in exclusive mode, std::unique_lock can be used)
  • The shared_lock class is movable, but not copyable -- it meets the requirements of MoveConstructible and MoveAssignable but not of CopyConstructible or CopyAssignable.
  • In a reader and write the situation (or producers-consumers), where there can be multiple readers and writers, usestd::shared_lock for readers, and use std::unique_lock for writers because only writers can change the state so they need the exclusiveness.

--

--

No responses yet