Fix cleanup race condition where objects might may not
be cleaned up correctly.

Change-Id: Ia48e06c3d050b6b39b39f8fdc9f0eb89b92fe1bf
diff --git a/rsContext.cpp b/rsContext.cpp
index c437d72..6a065b2 100644
--- a/rsContext.cpp
+++ b/rsContext.cpp
@@ -539,6 +539,7 @@
     }
     ObjectBase::zeroAllUserRef(this);
     LOGV("destroyWorkerThreadResources 2");
+    mExit = true;
 }
 
 void * Context::helperThreadProc(void *vrsc) {
@@ -713,6 +714,9 @@
 
 Context::~Context() {
     LOGV("Context::~Context");
+
+    mIO.mToCore.flush();
+    rsAssert(mExit);
     mExit = true;
     mPaused = false;
     void *res;