Process during its lifetime has 1 main thread and from 1 to 50 other worker threads. When main thread accepts new connection it saves it in boost::unordered_map, lets call it "new con container". Worker threads time to time check "new con container" for new connections. For sync purposes there is one boost::mutex. When main thread writes to "new con container" it locks this mutex. Worker threads while checking this container also lock the mutex.
Is there way for worker threads not to lock the mutex and thread-safely read from "new con container" ? Worker threads do real-time operations on sockets, so locking mutex beats on performance.
If you have a single writer and multiple readers consider using shared_mutex:
The class boost::shared_mutex provides an implementation of a multiple-reader / single-writer mutex.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With