Don't check for thread running in terminateLoopSoon()
authorMarc Horowitz <mhorowitz@fb.com>
Fri, 11 Jul 2014 23:48:20 +0000 (16:48 -0700)
committerSara Golemon <sgolemon@fb.com>
Thu, 14 Aug 2014 18:49:04 +0000 (11:49 -0700)
commit2215f6c0fbbc6735ff5f2226a9b26e2413bb5196
tree74eac5b59b0483154cfe374e56f04c106a9cae8e
parent9633f4758812c7d964df15e5437a603e74c8ec35
Don't check for thread running in terminateLoopSoon()

Summary:
Consider this use case:
thread 1:
make an evb
create and start thread 2
do some work
evb->terminateLoopSoon()
join thread 2 with a timeout
thread 2:
do some initialization
evb->loop()
Normally, this all works fine.  However, if the work thread 1 has to do is sufficiently small, and no external input occurs (one of the thing the evb is doing is listening on a socket), then sometimes, terminateLoopSoon() happens before loop() is called (or at least, before loopThread_.store() happens). isRunning() in terminateLoopSoon() is false, and so stop_ is never set, and event_base_loopbreak() is never called. The join times out, and thread 2 is still running.  Removing the isRunning() check gives the desired behavior.

Test Plan:
In my ad hoc tests, this fix caused my threads to exit when
I wanted them to exit in a situation like the one above.

Reviewed By: andrewcox@fb.com

FB internal diff: D1455885

Tasks: 2057547
folly/io/async/EventBase.cpp
folly/io/async/EventBase.h
folly/io/test/EventBaseTest.cpp [new file with mode: 0644]