From 09c9dfa823e7f80bd379cae8a759264bccabbee3 Mon Sep 17 00:00:00 2001 From: Jing Li Date: Mon, 27 Jul 2020 14:51:43 +0800 Subject: [PATCH 1/3] fix the hang caused by pthread_cancel Signed-off-by: Jing Li --- Source/Lib/Codec/EbThreads.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Lib/Codec/EbThreads.c b/Source/Lib/Codec/EbThreads.c index d0b3c639f..6ea8c033b 100644 --- a/Source/Lib/Codec/EbThreads.c +++ b/Source/Lib/Codec/EbThreads.c @@ -80,8 +80,8 @@ EB_HANDLE EbCreateThread( if (ret != 0) { if (ret == EPERM) { - pthread_cancel(*((pthread_t*)threadHandle)); + pthread_join(*((pthread_t*)threadHandle), NULL); free(threadHandle); threadHandle = (pthread_t*)malloc(sizeof(pthread_t)); From f082b91ae57703628ab06d98b75073cc31dff052 Mon Sep 17 00:00:00 2001 From: Jun Tian Date: Mon, 10 Aug 2020 20:32:53 -0700 Subject: [PATCH 2/3] Clean up the code Signed-off-by: Jun Tian --- Source/Lib/Codec/EbThreads.c | 48 ++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 27 deletions(-) diff --git a/Source/Lib/Codec/EbThreads.c b/Source/Lib/Codec/EbThreads.c index 6ea8c033b..a08351a54 100644 --- a/Source/Lib/Codec/EbThreads.c +++ b/Source/Lib/Codec/EbThreads.c @@ -60,42 +60,36 @@ EB_HANDLE EbCreateThread( 0, // thread active when created NULL); // new thread ID #else + threadHandle = (pthread_t*) malloc(sizeof(pthread_t)); + if (threadHandle == NULL) + return NULL; + pthread_attr_t attr; - struct sched_param param = { - .sched_priority = 99 - }; pthread_attr_init(&attr); pthread_attr_setschedpolicy(&attr, SCHED_FIFO); - pthread_attr_setschedparam(&attr, ¶m); - pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED); - threadHandle = (pthread_t*) malloc(sizeof(pthread_t)); - if (threadHandle != NULL) { - int ret = pthread_create( + struct sched_param param = {.sched_priority = 99}; + pthread_attr_setschedparam(&attr, ¶m); + + int ret = pthread_create( (pthread_t*)threadHandle, // Thread handle - &attr, // attributes - threadFunction, // function to be run by new thread + &attr, // attributes + threadFunction, // function to be run by new thread threadContext); + pthread_attr_destroy(&attr); - if (ret != 0) { - if (ret == EPERM) { - pthread_cancel(*((pthread_t*)threadHandle)); - pthread_join(*((pthread_t*)threadHandle), NULL); - free(threadHandle); - - threadHandle = (pthread_t*)malloc(sizeof(pthread_t)); - if (threadHandle != NULL) { - pthread_create( - (pthread_t*)threadHandle, // Thread handle - (const pthread_attr_t*)EB_NULL, // attributes - threadFunction, // function to be run by new thread - threadContext); - } - } - } + if (ret == EPERM) { + ret = pthread_create( + (pthread_t*)threadHandle, // Thread handle + (const pthread_attr_t*)EB_NULL, // attributes + threadFunction, // function to be run by new thread + threadContext); + } + if(ret != 0) { + free(threadHandle); + return NULL; } - pthread_attr_destroy(&attr); #endif // _WIN32 return threadHandle; From 3ca70fbc76b5e1d07958c953b89f14b3a8608c47 Mon Sep 17 00:00:00 2001 From: Jun Date: Tue, 11 Aug 2020 13:46:26 -0700 Subject: [PATCH 3/3] Update Source/Lib/Codec/EbThreads.c Co-authored-by: Christopher Degawa --- Source/Lib/Codec/EbThreads.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Source/Lib/Codec/EbThreads.c b/Source/Lib/Codec/EbThreads.c index a08351a54..1c47e8d58 100644 --- a/Source/Lib/Codec/EbThreads.c +++ b/Source/Lib/Codec/EbThreads.c @@ -69,8 +69,7 @@ EB_HANDLE EbCreateThread( pthread_attr_setschedpolicy(&attr, SCHED_FIFO); pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED); - struct sched_param param = {.sched_priority = 99}; - pthread_attr_setschedparam(&attr, ¶m); + pthread_attr_setschedparam(&attr, &(struct sched_param){.sched_priority = 99}); int ret = pthread_create( (pthread_t*)threadHandle, // Thread handle