trantor
trantor copied to clipboard
Make trantor::Logger::setOutputFunction thread safe
The call to the trantor::Logger::setOutputFunction is not thread safe:
https://github.com/an-tao/trantor/blob/8bf280ba043eb77c3eb02121065e0891a9a4f431/trantor/utils/Logger.h#L124-L139
2 threads can simultaneously set the values, or at least 1 simulaneous reader can read the value during the change of output function.
Proposal solution:
Use std::shared_mutex here. Use exclusive lock during modification and shared lock during the reading. This sure will consume some performance, but at least will be thread-safe.