Skip to content
This repository was 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 1 commit
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
2 changes: 1 addition & 1 deletion Source/Lib/Codec/EbThreads.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ EB_HANDLE EbCreateThread(

if (ret != 0) {
if (ret == EPERM) {

pthread_cancel(*((pthread_t*)threadHandle));
pthread_join(*((pthread_t*)threadHandle), NULL);
Copy link
Contributor

@tianjunwork tianjunwork Jul 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

       int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
                          void *(*start_routine) (void *), void *arg); 
 On success, pthread_create() returns 0; on error, it returns an error number, and the contents of *thread are undefined.

from: https://man7.org/linux/man-pages/man3/pthread_create.3.html.
Since *thread is undefined, do we even need to call pthread_cancel and pthread_join in this case?

Copy link
Contributor

@intelmark intelmark Jul 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In either case the two levels of return code checking can be condensed (i.e. ret != 0) is not needed.

if (ret == EPERM) is sufficient.

    if (ret != 0) {
        if (ret == EPERM) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

       int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
                          void *(*start_routine) (void *), void *arg); 
 On success, pthread_create() returns 0; on error, it returns an error number, and the contents of *thread are undefined.

from: https://man7.org/linux/man-pages/man3/pthread_create.3.html.
Since *thread is undefined, do we even need to call pthread_cancel and pthread_join in this case?

good question:), actually I don't think it's a good idea to turn set the thread policy to real time, it will drain the CPU. Of course it's good for encoding, and can have a little better encoder performance. But in real use case where you have other components like decoders/demuxers etc, doing so will not end up well

free(threadHandle);

threadHandle = (pthread_t*)malloc(sizeof(pthread_t));
Expand Down