[WRTjs][VD] Waitting ReallaunchWorker thread exit before app is terminated 02/317402/2 submit/tizen/20240915.160017
authorzhaosy <shiyusy.zhao@samsung.com>
Tue, 10 Sep 2024 02:23:59 +0000 (10:23 +0800)
committerBot Blink <blinkbot@samsung.com>
Sat, 14 Sep 2024 08:51:26 +0000 (08:51 +0000)
Both in main thread and ReallaunchWorker thread, security manager api is used.
If main thread exit, but ReallaunchWorker still is calling security manager api,
then the global variate of security manager is destroyed, but ReallaunchWorker
still is using it, then app is crashed.

So before app is terminated, join ReallaunchWorker thread.

Change-Id: I9458f53f9f506a9dbd71514558f33bde4051c7a4
Signed-off-by: zhaosy <shiyusy.zhao@samsung.com>
wrt/src/app/tv/wrt_main_delegate_tv.cc
wrt/src/app/tv/wrt_main_delegate_tv.h
wrt/src/browser/tv/native_web_runtime_delegate_tv.cc

index 776851f3cc00c82dc3c0b47fd35c3ddf0fae7576..307504324a0e212b9f47e527717e6de56c5e8034 100644 (file)
@@ -86,6 +86,7 @@ const char* kZoneLibPath = LIB_PATH "/libzone.so.5";
 
 std::mutex prelaunch_mutex;
 std::mutex reallaunch_mutex;
+std::thread reallaunch_worker;
 std::string prelaunch_pkg_id;
 
 bool CheckWindowManagerReady() {
@@ -227,6 +228,14 @@ void WRTMainDelegateTV::GroupZygoteProcess(bool is_oom) {
 #endif
 }
 
+// static
+void WRTMainDelegateTV::ReallaunchWorkerJoin() {
+  if (reallaunch_worker.joinable())
+    reallaunch_worker.join();
+
+  LOG(INFO) << "ReallaunchWorker thread exit";
+}
+
 void WRTMainDelegateTV::CreateWorkers() {
   prelaunch_mutex.lock();
   reallaunch_mutex.lock();
@@ -242,7 +251,7 @@ void WRTMainDelegateTV::CreateWorkers() {
   });
   prelaunch_worker.detach();
 
-  std::thread reallaunch_worker([]() -> void {
+  reallaunch_worker = std::thread([]() -> void {
     InitializeBeforeRealLaunch();
 
     // wake-up by real launch
@@ -256,8 +265,6 @@ void WRTMainDelegateTV::CreateWorkers() {
     GroupZygoteProcess(false);
     reallaunch_mutex.unlock();
   });
-  reallaunch_worker.detach();
-
 }
 
 void WRTMainDelegateTV::LoaderCreated() {
index 1f398cd9cb2bf861b657a3f37db6ed6dfd3d82db..4f235a254152d3d6fbef82a0ac65fb46cc8fc560 100644 (file)
@@ -19,6 +19,7 @@ class WRTMainDelegateTV : public WRTMainDelegate {
   ~WRTMainDelegateTV() {}
 
   static void GroupZygoteProcess(bool is_oom);
+  static void ReallaunchWorkerJoin();
 
  private:
   absl::optional<int> BasicStartupComplete() override;
index 069f29e6440b8fa410d9a4c7f01bd5c2c7281160..3863ab72028b3f1a229aecf444f5fbc171517519 100644 (file)
@@ -347,6 +347,8 @@ void NativeWebRuntimeDelegateTV::RequestQuit() {
   auto native_window_tv = WRTNativeWindowTV::GetMainNativeWindow();
   if (native_window_tv)
     native_window_tv->HideEarlyIfNecessary();
+
+  WRTMainDelegateTV::ReallaunchWorkerJoin();
 }
 
 std::string NativeWebRuntimeDelegateTV::CheckPrivilege(