Project

General

Profile

Task #2513

Updated by Junxiao Shi over 9 years ago

To Current way 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: 

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

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

 [boost::lockfree::queue](http://www.boost.org/doc/libs/1_53_0/doc/html/boost/lockfree/queue.html) should be used. 
 When Boost.Lockfree library is not available, a regular queue with `std::lock_guard` should be used. 

 The design of logging thread should be flexible about the number of 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