Why does the race detector set atexit_sleep_ms=1000 by default?

351 views
Skip to first unread message

Rémy Oudompheng

unread,
Jan 27, 2013, 1:20:51 PM1/27/13
to golang-nuts
Hello,

Race detection enabled binaries all sleep for 1 second before exiting.
Why is it so? I have to set GORACE=atexit_sleep_ms=0 to make it run normally.

Rémy.

minux

unread,
Jan 27, 2013, 1:41:45 PM1/27/13
to Rémy Oudompheng, Dmitry Vyukov, golang-nuts
On Mon, Jan 28, 2013 at 2:20 AM, Rémy Oudompheng <remyoud...@gmail.com> wrote:
Race detection enabled binaries all sleep for 1 second before exiting.
Why is it so? I have to set GORACE=atexit_sleep_ms=0 to make it run normally.
it aims to catch races involving C's atexit().
however, Go doesn't have atexit() so i think we can apply this patch to compiler_rt.

diff --git a/lib/tsan/rtl/tsan_flags.cc b/lib/tsan/rtl/tsan_flags.cc
index 88c4bb6..f0bd238 100644
--- a/lib/tsan/rtl/tsan_flags.cc
+++ b/lib/tsan/rtl/tsan_flags.cc
@@ -50,7 +50,7 @@ void InitializeFlags(Flags *f, const char *env) {
   f->suppressions = "";
   f->exitcode = 66;
   f->log_path = "stderr";
-  f->atexit_sleep_ms = 1000;
+  f->atexit_sleep_ms = kGoMode ? 0 : 1000; // no atexit() for Go
   f->verbosity = 0;
   f->profile_memory = "";
   f->flush_memory_ms = 0;

Dmitry Vyukov

unread,
Jan 30, 2013, 11:48:27 AM1/30/13
to golan...@googlegroups.com, Rémy Oudompheng, Dmitry Vyukov
Hi,

atexit_sleep_ms had proven to be extremely useful in C++ land to catch races between background threads and destructors of globals/function static objects.
I don't remember any Go atexit races (but I've seen much less Go races than C++ races, though). But the idea that you may have:

func main() {
  ...
  go backgroundProcess(...)
  ...
  ...
  foo.Shutdown()
}

func backgroundProcess(...) {
  for {
    time.Sleep(time.Second)
    foo.DoSomething()
  }
}

Here we have a race between foo.DoSomething() and foo.Shutdown(), but it unlikely will be found w/o atexit_sleep_ms.

Can you describe the context in which you need to set atexit_sleep_ms=0?
The concern is that if we set it to 0, since it only leads to false negatives, nobody will ever turn it on.

Reply all
Reply to author
Forward
0 new messages