When talking about thread-safety, there are 2 types of things to consider:
Based on your application, you can fine tune any of the above to suit your needs:
- use it as single threaded
- use TSS (Thread Specific Storage)
- use TSS - have some data you modify thread-safe(using mutexes), and have each thread cache the value, and refresh at a given period (very efficient)
- initialize your logger/filter only once, and once it's initialized, always use that value (very efficient)
- thread-safe (use mutexes) - every access uses a mutex; very slow in comparison to the above methods
In addition to the above, for loggers, you can have an even faster method of writing the messages to their destinations: on a dedicated thread.
The easiest way to specify the logger and filter classes, is to customize the lib to suit your application's needs.
Alternatively, you can define them manually:
logger<default_, default_, writer::threading::no_ts> - single threaded logger
logger<default_, default_, writer::threading::ts_write> - thread-safe logger
logger<default_, default_, writer::threading::on_dedicated_thread> - thread-safe logger, writing on dedicated thread
Note: I recommend defining loggers manually only if you know the lib very well. Otherwise, choose one of these:
Copyright John Torjo © 2007
Have a question/ suggestion/ comment? Send me feedback