Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes rare crash when lowering number of threads #2013

Merged
merged 1 commit into from
Sep 24, 2018

Conversation

ThiagoIze
Copy link
Collaborator

Description

More details, including a hopefully easy repro that works on OSX, are in #1991.

The way this fix works is that instead of detaching threads, which by bad luck might stay running and access thread pool data after the thread pool is destroyed, we stay attached and move the threads into a list of threads that we have to explicitly wait on to be finished, just like we already do for the active threads.

Tests

The crash is very hard to reproduce without adding a 1s sleep, and even then I suspect the 1s worked for me because my process runs in under 1s. Maybe you'll need to sleep for at least as long as it takes to go from lowering the number of threads to terminating the process so that we can be assured the detached threads survive to the end?

Checklist:

  • [ x] I have read the contribution guidelines.
  • If this is more extensive than a small change to existing code, I
    have previously submitted a Contributor License Agreement
    (individual, and if there is any way my
    employers might think my programming belongs to them, then also
    corporate).
  • I have updated the documentation, if applicable.
  • I have ensured that the change is tested somewhere in the testsuite
    (adding new test cases if necessary).
  • [x ] My code follows the prevailing code style of this project.

…cess threads to be detached, and one of these deteached threads happens to not yet have terminated before the thread pool is destroyed.
@lgritz
Copy link
Collaborator

lgritz commented Sep 24, 2018

LGTM, thanks for the fix to this tricky issue.
Merging.

@lgritz lgritz merged commit ebc51c6 into AcademySoftwareFoundation:master Sep 24, 2018
@lgritz lgritz mentioned this pull request Sep 24, 2018
lgritz pushed a commit to lgritz/OpenImageIO that referenced this pull request Sep 24, 2018
…cess threads to be detached, and one of these deteached threads happens to not yet have terminated before the thread pool is destroyed. (AcademySoftwareFoundation#2013)
@lgritz
Copy link
Collaborator

lgritz commented Sep 24, 2018

Backport to 1.8 as well, I presume?

@ThiagoIze
Copy link
Collaborator Author

I haven't tested on 1.8, but looking at the code it does seem like it would benefit as well.

@ThiagoIze ThiagoIze deleted the threadpool_crash branch September 24, 2018 09:47
@lgritz
Copy link
Collaborator

lgritz commented Sep 24, 2018

Merged into 1.8.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants