title: Android Native libs - how are writes to log serialized
body: <p>I've been looking at <code>libbinder.so</code>, specifically <a href="https://android.googlesource.com/platform/frameworks/native/+/jb-mr1-release/libs/binder/IPCThreadState.cpp#781" rel="nofollow noreferrer">IPCThreadState.cpp, line 781</a></p>
  
  <p>In <code>libbinder.so</code>, writes are serialized using this line: <code>TextOutput::Bundle _b(alog);</code> which locks a mutex.</p>
  
  <p>The "call tree" for the writes is:<br>
  <code>alog &lt;&lt; "Sending commands to driver: " &lt;&lt; indent;</code>  </p>
  
  <pre><code>template&lt;typename T&gt;
  TextOutput&amp; operator&lt;&lt;(TextOutput&amp; to, const T&amp; val)
  {
      std::stringstream strbuf;
      strbuf &lt;&lt; val;
      std::string str = strbuf.str();
      to.print(str.c_str(), str.size());
      return to;
  }
  </code></pre>
  
  <p><code>status_t BufferedTextOutput::print(const char* txt, size_t len)</code></p>
  
  <pre><code>virtual status_t writeLines(const struct iovec&amp; vec, size_t N)
  {
          //android_writevLog(&amp;vec, N);       &lt;-- this is now a no-op
          if (N != 1) ALOGI("WARNING: writeLines N=%zu\n", N);
          ALOGI("%.*s", (int)vec.iov_len, (const char*) vec.iov_base);
          return NO_ERROR;
  }
  </code></pre>
  
  <p><code>#define ALOGI(x...) fprintf(stderr, "svcmgr: " x)</code></p>
  
  <p>I understand how writes to log are serialized within <code>libbinder.so</code> but how are writes serialized between multiple <code>.so</code> libraries?</p>
  
  <p><code>libbinder.so</code> writes to <code>stderr</code> but surely there are other libs that also write to <code>stderr</code>.</p>