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

Helper threads never finalize #8

Closed
ogunden opened this issue Oct 30, 2015 · 4 comments
Closed

Helper threads never finalize #8

ogunden opened this issue Oct 30, 2015 · 4 comments

Comments

@ogunden
Copy link

ogunden commented Oct 30, 2015

It appears that when using In_thread.Helper_thread, in spite of what is indicated by the docs:

create uses a thread from Async's thread pool, reserving that thread for exclusive use by the helper thread until the helper thread is no longer used (specifically, finalized and is finished with all its work), at which point the thread is made available for general use by the pool.

helper threads are in fact never finalized and never made available for general use by the pool.

The reason for this seems to be that Thread_pool.Thread.t's type state, when in Helper mode, references the Helper_thread.t (and thus the Helper_thread cannot be finalized), and the only way that a Thread can leave Helper mode is through maybe_finish_helper_thread, which only does something if the state of the helper thread is Finishing, which is only the case if finished_with_helper_thread is called, which only happens when the In_thread.Helper_thread is finalized (which it can't be because it's in Helper mode, a catch-22).

If In_thread.Helper_thread exposed a call to finished_with_helper_thread, then the user could at least manually free up the thread. Or you can work around it by using Thread_pool directly instead of using In_thread, but then you have to reimplement In_thread.run, a non-trivial function. Otherwise, there is probably a way around the catch so that it gets properly gc'd but I don't have a solution right off.

@ghost
Copy link

ghost commented Nov 2, 2015

I don't have time to look into this right now, but I left a note internally about this

@bmillwood
Copy link
Contributor

We've confirmed this is a bug, and a fix will be on the way soon.

@bmillwood
Copy link
Contributor

I never followed up on this but I see what looks like a test for this in our internal test suite, so I'm guessing this was fixed as planned long ago.

@ogunden
Copy link
Author

ogunden commented Aug 2, 2017

I think this issue actually still exists. I've been meaning to write a test case to demonstrate it but haven't had a chance yet. I'll share the results here when I do.

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

No branches or pull requests

2 participants