[core] Block in Mailbox::close() until neither receive nor push are in progress

Otherwise, an ActorRef that's in the process of sending a message could attempt to access an invalid Scheduler reference:

      Thread 1                     Thread 2
--------------------------------------------------
 Scheduler::Scheduler
     Actor::Actor
                              weakMailbox.lock()
     Actor::~Actor
 Scheduler::~Scheduler
                               mailbox->push()
                             scheduler.schedule() 💣
This commit is contained in:
John Firebaugh
2017-05-22 16:05:58 -07:00
parent 8b448786fe
commit 2c8343aa82
3 changed files with 79 additions and 12 deletions

View File

@@ -23,8 +23,10 @@ public:
private:
Scheduler& scheduler;
std::mutex closingMutex;
bool closing { false };
std::mutex receivingMutex;
std::mutex pushingMutex;
bool closed { false };
std::mutex queueMutex;
std::queue<std::unique_ptr<Message>> queue;