From: Bang Kwang-Min Date: Thu, 9 May 2013 06:30:35 +0000 (+0900) Subject: pthread_join for ending of queue-manager thread X-Git-Tag: submit/tizen_2.1/20130514.052227~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=20c983e63bbe00608b0705057b4d2e0295730a66;p=platform%2Fframework%2Fweb%2Fdownload-provider.git pthread_join for ending of queue-manager thread [issue#] N_SE-37946 [cause] queue manager thread still work even if main thread free all resources [solution] wait the ending of queue manager thread before free resources Change-Id: Ib7007b3466b9eb0392946390d52150bbd96d29bb --- diff --git a/provider/download-provider-main.c b/provider/download-provider-main.c index 96495ec..630f0c7 100755 --- a/provider/download-provider-main.c +++ b/provider/download-provider-main.c @@ -39,6 +39,7 @@ // declare functions int dp_lock_pid(char *path); void *dp_thread_requests_manager(void *arg); +static pthread_t g_dp_thread_queue_manager_pid = 0; // declare global variables // need for libsoup, decided the life-time by mainloop. @@ -105,7 +106,7 @@ static gboolean __dp_idle_start_service(void *data) // create thread for managing QUEUEs if (pthread_create - (&thread_pid, &thread_attr, dp_thread_queue_manager, + (&g_dp_thread_queue_manager_pid, NULL, dp_thread_queue_manager, data) != 0) { TRACE_STRERROR ("failed to create pthread for run_manage_download_server"); @@ -299,6 +300,15 @@ DOWNLOAD_EXIT : dp_socket_free(privates->listen_fd); privates->listen_fd = -1; } + if (g_dp_thread_queue_manager_pid > 0 && + pthread_kill(g_dp_thread_queue_manager_pid, 0) != ESRCH) { + //pthread_cancel(g_dp_thread_queue_manager_pid); + //send signal to queue thread + dp_thread_queue_manager_wake_up(); + int status; + pthread_join(g_dp_thread_queue_manager_pid, (void **)&status); + g_dp_thread_queue_manager_pid = 0; + } dp_request_slots_free(privates->requests, DP_MAX_REQUEST); privates->requests = NULL; dp_client_group_slots_free(privates->groups, DP_MAX_GROUP); @@ -308,9 +318,6 @@ DOWNLOAD_EXIT : } dp_db_close(); - //send signal to queue thread - dp_thread_queue_manager_wake_up(); - // if exit socket file, delete it if (access(DP_IPC, F_OK) == 0) { unlink(DP_IPC);