Fix a race on destruction of ScopedEventBaseThread
authorVictor Zverovich <viz@fb.com>
Thu, 11 May 2017 16:19:42 +0000 (09:19 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Thu, 11 May 2017 16:25:50 +0000 (09:25 -0700)
commite17fce322760eddc0d598a2044cfd639894d75be
tree8aebef1652b036073c0421ffce20667886b12578
parent9c626faa547649a8e110cea91126c17bcfcb0f3f
Fix a race on destruction of ScopedEventBaseThread

Summary:
This diff fixes a race that happens on destruction of `ScopedEventBaseThread`.

```
Thread1: ~ScopedEventBaseThread()
Thread1: eb_.terminateLoopSoon() <- preempted just after stop_ = true
Thread2: eb->loopForever() in run(...) exits because stop_ is true
Thread2: ...
Thread2: eb->~EventBase()
Thread1: queue_->putMessage(nullptr) <- accesses destroyed EventBase
```

Reviewed By: yfeldblum

Differential Revision: D5042654

fbshipit-source-id: 95515ed7cde09ff5f125ef121bea86ab3907f98a
folly/io/async/ScopedEventBaseThread.cpp
folly/io/async/ScopedEventBaseThread.h