status-im / nim-chronos

Chronos - An efficient library for asynchronous programming
https://status-im.github.io/nim-chronos/
Apache License 2.0
362 stars 51 forks source link

Allow to close thread dispatcher #326

Open Menduist opened 2 years ago

Menduist commented 2 years ago

When a thread finishes, there is currently no way to release the resources of the dispatcher. Which on linux, include a FD & relatively big buffer for epoll

We could use onThreadDestruction to call "close" automatically, but that raises questions in what to do with pending futures

cheatfate commented 2 years ago

Closing IOCP port or EPOLL/KQUEUE file descriptor do not closes all the files/sockets/pipes which was registered with it. So with this PR the only resource you are cleaning is IOCP port or EPOLL/KQUEUE file descriptor - nothing more. Your PR do not even check if there some descriptors registered in IOCP/EPOLL/KQUEUE.

Menduist commented 2 years ago

I would argue that the sockets the user opened are to be closed by the user

We can imagine that a user does something where he opens a socket on one thread, and then switch its processing to another thread, so we shouldn't close it if he stops the first thread

cheatfate commented 2 years ago

Of course, but i think the main idea of calling poll() in loop is to allow thread to get into state when there is no more unreleased resources except IOCP and KQUEUE/EPOLL data structure and descriptor.