C++ implementation of the Google logging module
Go to file
Kenny Yu 4764ca65f5 Annotate LOG_EVERY_N macros as a benign race for TSAN
Summary:
Issue #80 points out several places in glog where TSAN discovers
false positives. One of these places is in the `LOG_EVERY_N` macros.
These macros are implemented by maintaining a static unprotected
integer counter, and TSAN will report data races on these counters.

Here is a minimum example to reproduce the data race:

```

void logging() {
  for (int i = 0; i < 300; ++i) {
    LOG_EVERY_N(INFO, 2) << "foo";
  }
}

int main() {
  auto t1 = std::thread(logging);
  auto t2 = std::thread(logging);
  t1.join();
  t2.join();
  return 0;
}
```

And here is the TSAN report:

```
WARNING: ThreadSanitizer: data race (pid=776850)
  Write of size 4 at 0x558de483f684 by thread T2:
    #0 logging()
    #1 void std::_Bind_simple<void (*())()>::_M_invoke<>(std::_Index_tuple<>)
    #2 std::_Bind_simple<void (*())()>::operator()()
    #3 std:🧵:_Impl<std::_Bind_simple<void (*())()> >::_M_run()
    #4 execute_native_thread_routine

  Previous write of size 4 at 0x558de483f684 by thread T1:
    #0 logging()
    #1 void std::_Bind_simple<void (*())()>::_M_invoke<>(std::_Index_tuple<>)
    #2 std::_Bind_simple<void (*())()>::operator()()
    #3 std:🧵:_Impl<std::_Bind_simple<void (*())()> >::_M_run()
    #4 execute_native_thread_routine

  Location is global '<null>' at 0x000000000000 (main+0x00000011c684)

  Thread T2 (tid=776857, running) created by main thread at:
    #0 pthread_create
    #1 __gthread_create
    #2 std:🧵:_M_start_thread(std::shared_ptr<std:🧵:_Impl_base>, void (*)())
    #3 main

  Thread T1 (tid=776856, running) created by main thread at:
    #0 pthread_create
    #1 __gthread_create
    #2 std:🧵:_M_start_thread(std::shared_ptr<std:🧵:_Impl_base>, void (*)())
    #3 main

SUMMARY: ThreadSanitizer: data race in logging()
```

To avoid noisy TSAN reports and also avoid adding a performance hit, this
change will mark these counters as benign races so that TSAN will not report
them. This change will only have an effect if we are compiling with TSAN;
there are no changes if we are not building with TSAN.

With this change, the above example no longer reports a data race when built
and run with TSAN.
2017-11-03 17:32:47 -07:00
cmake cmake: fixed gflags namespace detection (fixes #193) 2017-07-09 15:48:13 +02:00
doc Document update: how to modify FLAGS_* in glog 2013-01-25 06:03:56 +00:00
m4 Run autoreconf on ubuntu precise 2013-01-09 13:26:44 +00:00
packages glog: release 0.3.5 2017-05-09 16:27:57 +09:00
src Annotate LOG_EVERY_N macros as a benign race for TSAN 2017-11-03 17:32:47 -07:00
vsprojects Add static library project and its unittest. 2009-01-23 18:56:19 +00:00
.gitignore Update gitignore for CMake and Visual Studio 2017-07-26 11:34:52 -07:00
AUTHORS Add Andrew Schwartzmeyer to authors and contributors 2017-06-26 16:21:10 -07:00
autogen.sh Remove files generated by autotools 2017-05-12 14:53:39 +09:00
ChangeLog Release glog 0.3.3 2013-02-01 06:20:46 +00:00
CMakeLists.txt Merge pull request #245 from DariuszOstolski/issue211 2017-10-20 16:09:28 +09:00
configure.ac Fix username lookup in case of missing USER environment variable 2017-09-19 22:23:53 +02:00
CONTRIBUTING.md Add the typical Google contributors and authors files. 2015-03-16 10:50:32 +00:00
CONTRIBUTORS Add Jim Ray to CONTRIBUTORS 2017-08-06 00:13:30 -07:00
COPYING A bug fix for Windows: Use GetSystemTimeAsFileTime instead of GetSystemTime. SYSTEMTIME's mSecond is not a unix time but like tm.tm_sec. 2009-04-09 07:49:44 +00:00
glog-config.cmake.in cmake: allow to refer to imported glog target as glog::glog 2016-01-08 14:55:58 +01:00
INSTALL Fix regression of r23. 2009-07-08 15:38:35 +00:00
libglog.pc.in Generation of pkg-config metadata file. 2009-04-10 05:49:58 +00:00
ltmain.sh Run autoreconf on ubuntu precise 2013-01-09 13:26:44 +00:00
Makefile.am glog: release 0.3.4 2015-03-09 11:45:07 +09:00
NEWS glog 0.1 2008-10-07 05:43:05 +00:00
README Remove files generated by autotools 2017-05-12 14:53:39 +09:00
README.windows Update Windows readme for CMake 2017-07-26 11:35:04 -07:00

This repository contains a C++ implementation of the Google logging
module.  Documentation for the implementation is in doc/.

See INSTALL for (generic) installation instructions for C++: basically
   ./autogen.sh && ./configure && make && make install