Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

fix the hang caused by pthread_cancel #564

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 21 additions & 27 deletions Source/Lib/Codec/EbThreads.c
Original file line number Diff line number Diff line change
Expand Up @@ -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, &param);

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, &param);
tianjunwork marked this conversation as resolved.
Show resolved Hide resolved

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));
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;
Expand Down