Skip to content

Conversation

centurysys
Copy link
Contributor

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.


when defined(nuttx):
proc addAtExit(quitProc: proc() {.noconv, cdecl.}) {.
importc: "atexit", header: "<stdlib.h>".}
Copy link
Member

Choose a reason for hiding this comment

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

Why not use addQuitProc?

Copy link
Contributor Author

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".}

Copy link
Contributor Author

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).

@centurysys centurysys force-pushed the feature/nuttx-asyncdispatch-destructor branch from 8647432 to e2ba3ab Compare February 25, 2023 02:58
@centurysys centurysys force-pushed the feature/nuttx-asyncdispatch-destructor branch from e2ba3ab to 57ccf45 Compare February 25, 2023 12:50
@centurysys
Copy link
Contributor Author

I was able to get it to use std/exitprocs. Please confirm.

@Araq Araq merged commit dd629c8 into nim-lang:devel Feb 28, 2023
@github-actions
Copy link
Contributor

Thanks for your hard work on this PR!
The lines below are statistics of the Nim compiler built from dd629c8

Hint: mm: orc; opt: speed; options: -d:release
166274 lines; 8.668s; 610.68MiB peakmem

@centurysys centurysys deleted the feature/nuttx-asyncdispatch-destructor branch March 1, 2023 10:44
capocasa pushed a commit to capocasa/Nim that referenced this pull request Mar 31, 2023
…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]>
bung87 pushed a commit to bung87/Nim that referenced this pull request Jul 29, 2023
…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]>
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