- 
                Notifications
    
You must be signed in to change notification settings  - Fork 153
 
Open
Description
The call to the trantor::Logger::setOutputFunction is not thread safe:
trantor/trantor/utils/Logger.h
Lines 124 to 139 in 8bf280b
| static void setOutputFunction( | |
| std::function<void(const char *msg, const uint64_t len)> outputFunc, | |
| std::function<void()> flushFunc, | |
| int index = -1) | |
| { | |
| if (index < 0) | |
| { | |
| outputFunc_() = outputFunc; | |
| flushFunc_() = flushFunc; | |
| } | |
| else | |
| { | |
| outputFunc_(index) = outputFunc; | |
| flushFunc_(index) = flushFunc; | |
| } | |
| } | 
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.
Metadata
Metadata
Assignees
Labels
No labels