• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
4<title>Why log records are weakly ordered in a multithreaded application?</title>
5<link rel="stylesheet" href="../../../../../../doc/src/boostbook.css" type="text/css">
6<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
7<link rel="home" href="../../index.html" title="Chapter 1. Boost.Log v2">
8<link rel="up" href="../rationale.html" title="Rationale and FAQ">
9<link rel="prev" href="why_weak_scoped_attributes.html" title="Why scoped attributes don't override existing attributes?">
10<link rel="next" href="why_attribute_manips_dont_affect_filters.html" title="Why attributes set with stream manipulators do not participate in filtering?">
11</head>
12<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
13<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td></tr></table>
14<hr>
15<div class="spirit-nav">
16<a accesskey="p" href="why_weak_scoped_attributes.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../rationale.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="why_attribute_manips_dont_affect_filters.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
17</div>
18<div class="section">
19<div class="titlepage"><div><div><h3 class="title">
20<a name="log.rationale.why_weak_record_ordering"></a><a class="link" href="why_weak_record_ordering.html" title="Why log records are weakly ordered in a multithreaded application?">Why log records
21      are weakly ordered in a multithreaded application?</a>
22</h3></div></div></div>
23<p>
24        Although the library guarantees that log records made in a given thread are
25        always delivered to sinks in the same order as they were made in, the library
26        cannot provide such guarantee for different threads. For instance, it is
27        possible that thread A emits a log record and gets preempted, then thread
28        B emits its log record and manages to deliver it to a sink before being preempted.
29        The resulting log will contain log record from thread B before the record
30        made in thread A. However, attribute values attached to the records will
31        always be actual with regard to the moment of emitting the record and not
32        the moment of passing the record to the sink. This is the reason for a strange,
33        at first glance, situation when a log record with an earlier time stamp follows
34        a record with a later time stamp. The problem appears quite rarely, usually
35        when thread contention on logging is very high.
36      </p>
37<p>
38        There are few possible ways to cope with the problem:
39      </p>
40<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
41<li class="listitem">
42            Enforce strict serialization of log record being made throughout the
43            application. This solution implies a severe performance impact in multithreaded
44            applications because log records that otherwise could be processed concurrently
45            would have to go serial. Since this controverses one of the <a class="link" href="../../index.html#log.moti" title="Motivation">main
46            library goals</a>, it was rejected.
47          </li>
48<li class="listitem">
49            Attempt to maintain log record ordering on the sink level. This solution
50            is more or less viable. On the downside, it would introduce log record
51            buffering, which in turn would compromise logs reliability. In the case
52            of application crash all buffered records would be lost.
53          </li>
54<li class="listitem">
55            Bear with the problem and let mis-ordered records appear in log files
56            occasionally. Order log records upon reading the files, if needed.
57          </li>
58</ul></div>
59<p>
60        The second solution was implemented as a special policy for the <a class="link" href="../detailed/sink_frontends.html#log.detailed.sink_frontends.async" title="Asynchronous sink frontend">asynchronous
61        sink frontend</a>.
62      </p>
63</div>
64<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
65<td align="left"></td>
66<td align="right"><div class="copyright-footer">Copyright © 2007-2019 Andrey Semashev<p>
67        Distributed under the Boost Software License, Version 1.0. (See accompanying
68        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>).
69      </p>
70</div></td>
71</tr></table>
72<hr>
73<div class="spirit-nav">
74<a accesskey="p" href="why_weak_scoped_attributes.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../rationale.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="why_attribute_manips_dont_affect_filters.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
75</div>
76</body>
77</html>
78