Don't bind process to make task for pushing thread pool 40/71840/3
authorKyungwook Tak <k.tak@samsung.com>
Fri, 27 May 2016 08:39:46 +0000 (17:39 +0900)
committerKyungwook Tak <k.tak@samsung.com>
Mon, 30 May 2016 02:07:57 +0000 (11:07 +0900)
Sometimes crash occured on dtor of binded std::function after moved to
thread pool task queue. We can avoid it by using inbuf as shared ptr so
as to being delivered into lamda capture.

Change-Id: I76d68d91ca75bdc0c37bfb5b125a1e2956744010
Signed-off-by: Kyungwook Tak <k.tak@samsung.com>
src/framework/service/server-service.cpp

index 3d66ce3..70c1bdc 100644 (file)
@@ -358,16 +358,15 @@ void ServerService::onMessageProcess(const ConnShPtr &connection)
                ThrowExc(InternalError, "Message from unknown sock id");
        }
 
-       auto inbuf = connection->receive();
-       auto task = [this, &connection, process](RawBuffer &buffer) {
-               auto outbuf = (*process)(connection, buffer);
+       auto inbufPtr = std::make_shared<RawBuffer>(connection->receive());
+
+       m_workqueue.submit([this, &connection, process, inbufPtr]() {
+               auto outbuf = (*process)(connection, *inbufPtr);
 
                connection->send(outbuf);
 
                CpuUsageManager::reset();
-       };
-
-       m_workqueue.submit(std::bind(task, std::move(inbuf)));
+       });
 }
 
 }