-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
asyncdispatch: for NuttX, add destructor to clear global dispatcher. #21432
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
asyncdispatch: for NuttX, add destructor to clear global dispatcher. #21432
Conversation
lib/pure/asyncdispatch.nim
Outdated
|
||
when defined(nuttx): | ||
proc addAtExit(quitProc: proc() {.noconv, cdecl.}) {. | ||
importc: "atexit", header: "<stdlib.h>".} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use addQuitProc?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was marked "deprecated" and I thought it would go away.
when not defined(nimPreviewSlimSystem):
proc addQuitProc*(quitProc: proc() {.noconv.}) {.
importc: "atexit", header: "<stdlib.h>", deprecated: "use exitprocs.addExitProc".}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the exitprocs, there is a "callClosures" that registers with the OS in atexit() and executes functions that the user registers.
Would it be a good idea to change it so that it executes while removing functions from the gFuns array?
(The second time the task is invoked, gFuns.len == 0, so atexit() will be executed again).
8647432
to
e2ba3ab
Compare
…sing atexit(). Signed-off-by: Takeyoshi Kikuchi <[email protected]>
e2ba3ab
to
57ccf45
Compare
Signed-off-by: Takeyoshi Kikuchi <[email protected]>
I was able to get it to use std/exitprocs. Please confirm. |
Thanks for your hard work on this PR! Hint: mm: orc; opt: speed; options: -d:release |
…im-lang#21432) * asyncdispatch: for NuttX, add destructor to clear global dispatcher using atexit(). Signed-off-by: Takeyoshi Kikuchi <[email protected]> * std: exitprocs: remove "when defined(nuttx)" block. Signed-off-by: Takeyoshi Kikuchi <[email protected]> --------- Signed-off-by: Takeyoshi Kikuchi <[email protected]>
…im-lang#21432) * asyncdispatch: for NuttX, add destructor to clear global dispatcher using atexit(). Signed-off-by: Takeyoshi Kikuchi <[email protected]> * std: exitprocs: remove "when defined(nuttx)" block. Signed-off-by: Takeyoshi Kikuchi <[email protected]> --------- Signed-off-by: Takeyoshi Kikuchi <[email protected]>
When the task ends, all opened file descriptors are closed by OS, but the memory is left as it is, so the gDisp(global dispatcher) is not released and the "value" of the epoll fd inside gDisp is left as it is.
Therefore, when the task was started a second time, it judged that epoll_create1() had already been executed, resulting in an error.
For NuttX only, I was able to deal with this by explicitly registering the process of clearing gDisp with atexit() before using the asyncdispatch function.