Subject: Re: [boost] [log] Is it lock free ?
From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2013-04-29 23:32:06
On Monday 29 April 2013 23:07:32 adrien courdavault wrote:
> I'm really interested by the new Log library.
> I would like to know if there is a part of this API that could be wait
> free, not the << operator perhaps, but a specific function to log a
> message without having to worry about a malloc or lock called inside
> the library.
> I would like to use this from a time critical thread.
The library is not lock-free, it will have to allocate dynamic memory and
obtain locks when processing log records (but not when you call operator<<
while composing the message).
However, the library is quite friendly to multithreaded applications. It uses
shared locks internally when possible, so different threads can process
records simultaneously. Synchronous sinks will block on contention, although
the library tries to avoid that when multiple sinks are used. You can try
using asynchronous sinks if that's the problem. asynchronous_sink<T,
unbounded_fifo_queue> uses a lock-free queue internally, so it will avoid
locking. Other types of queues will still use locking but the probability to
block on these locks is quite low.
I would also recommend using a decent memory allocator with the library, such
as TCMalloc. It uses thread-specific memory pools, which makes memory
allocations very fast and maybe even lock-free, although I haven't checked