change thread style
authorBang Kwang min <justine.bang@samsung.com>
Tue, 4 Sep 2012 08:02:55 +0000 (17:02 +0900)
committerBang Kwang min <justine.bang@samsung.com>
Wed, 5 Sep 2012 05:43:36 +0000 (14:43 +0900)
[Title] change thread style as detached
[Issue#] S1-8296
[Problem] tkill SIGABRT when turn off phone
[Cause] pthread_cancel bug
[Solution] detach the thread to free by itself.
[SCMRequest] N/A

Change-Id: I139b5a770fde2ffa01f5622a1755604635a709fa

src/download-provider-main.c

index 46a0334e940901565feb487f47a1c019983e88ac..4751fbaff2496c82134b9a0e225440d23b7ec1eb 100644 (file)
@@ -9,7 +9,6 @@
 #include "download-provider-log.h"
 
 GMainLoop *gMainLoop = 0;      // need for libsoup, decided the life-time by mainloop.
-pthread_t gRequestThreadPid;
 
 int lock_download_provider_pid(char *path);
 void *run_manage_download_server(void *args);
@@ -23,21 +22,26 @@ void TerminateDaemon(int signo)
 
 static gboolean CreateThreadFunc(void *data)
 {
+       pthread_t thread_pid;
        pthread_attr_t thread_attr;
        if (pthread_attr_init(&thread_attr) != 0) {
                TRACE_DEBUG_MSG("failed to init pthread attr");
-               if (g_main_loop_is_running(gMainLoop))
-                       g_main_loop_quit(gMainLoop);
+               TerminateDaemon(SIGTERM);
                return FALSE;
        }
+       if (pthread_attr_setdetachstate(&thread_attr,
+                                                                       PTHREAD_CREATE_DETACHED) != 0) {
+               TRACE_DEBUG_MSG("failed to set detach option");
+               TerminateDaemon(SIGTERM);
+               return 0;
+       }
        // create thread for receiving the client request.
        if (pthread_create
-               (&gRequestThreadPid, &thread_attr, run_manage_download_server,
+               (&thread_pid, &thread_attr, run_manage_download_server,
                data) != 0) {
                TRACE_DEBUG_MSG
                        ("failed to create pthread for run_manage_download_server");
-               if (g_main_loop_is_running(gMainLoop))
-                       g_main_loop_quit(gMainLoop);
+               TerminateDaemon(SIGTERM);
        }
        return FALSE;
 }
@@ -83,9 +87,6 @@ int main()
 
        TRACE_DEBUG_INFO_MSG("Download-Provider will be terminated.");
 
-       pthread_cancel(gRequestThreadPid);
-       pthread_join(gRequestThreadPid, NULL);
-
        // if exit socket file, delete it
        if (access(DOWNLOAD_PROVIDER_IPC, F_OK) == 0) {
                unlink(DOWNLOAD_PROVIDER_IPC);