Project

General

Profile

Task #2513

Updated by Junxiao Shi over 8 years ago

To ensure proper logging in a multi-threaded environment, currently we use `std::lock_guard` to prevent any race conditions. 

 This process can be optimized with the use of a lock-free queue(s): queue: 

 * individual threads (NFD and RIB) write logs, line by line, into lock-free queue(s) queues 
 * separate thread that pulls log lines from queue(s), both queues, and writes them into std::clog 

 ``` 
 |---------------| 
 | NFD thread      |    queue    |------------------| 
 |            push >>>>>>>>>>> pop                | 
 |---------------|           |                    | 
                           |    logging thread    >> std::clog 
 |---------------|           |                    | 
 |            push >>>>>>>>>>> pop                | 
 | RIB thread      |    queue    |------------------| 
 |---------------| 
 ``` 

 A lock-free queue, such as `boost::lockfree::queue` or `boost::lockfree:spsc_queue`, from [Boost.Lockfree](http://www.boost.org/doc/libs/1_53_0/doc/html/lockfree.html) library, [boost::lockfree::queue](http://www.boost.org/doc/libs/1_53_0/doc/html/boost/lockfree/queue.html) should be used. 
 On a platform where When Boost.Lockfree library is not available, a regular queue protected by with `std::lock_guard` could should be used. 

 The design of logging thread should be flexible about the number of log-generating threads. queues. 
 In the future, when we need to add a third log-generating thread to `nfd` process, the logging thread should not require a major change.

Back