Making the logging library thread-safe
We don’t know if a project that uses the logging library will be trying to log from multiple threads or a single thread. With an application, we’re in full control and can choose to use multiple threads or not. But a library, especially a logging library, often needs to be thread-safe. This means that the logging library needs to behave well when an application uses the library from multiple threads. Making code thread-safe adds some extra overhead to the code and is not needed if the library will only be used from a single thread.
What we need is a test that calls log
from multiple threads that are all running at the same time. Let’s write a test with the code we have now and see what happens. We’re going to be using the logging project in this section and adding a new file to the tests
folder called Thread.cpp
. The project structure will look like this with the new file added:
MereMemo project root folder
&...