Skip to content

Conversation

@PhilippMDoerner
Copy link

@PhilippMDoerner PhilippMDoerner commented May 21, 2024

First draft for what I learned with chronos in multithreading so far and how that could be turned into docs as discussed in #542 .

If you had a different vision @arnetheduck let me know, I'll see what I can do.

Note that I think a rather obvious question that I do not yet know the answer for is:
"What do I do when I want the thread to end, but the Dispatcher still has work on it? How do I tell it to process the remaining work?"

If I had an answer to that I'd gladly add an example to the docs.

proc cleanupThread*() {.gcsafe, raises: [].}=
{.cast(gcsafe).}:
try:
`=destroy`(getThreadDispatcher())
Copy link
Member

Choose a reason for hiding this comment

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

Finally had time to look into this problem a bit more - while this trick releases the (ORC) memory held by the dispatcher, the bigger issue is that the other resources (such as the IOCP/selector) still cause a leak per thread (since one selector is allocated per thread).

Instead of this partial solution, I think that the documentation would do better to document the status quo:

"On thread exit, some thread-local resources used by chronos are not released - it is recommended to use a thread pool and reuse chronos threads for this reason. For more information, see issue https:/// ..."

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