I am trying to run a task that uses asyncdispatch on RTOS(NuttX).
When I tried to launch multiple tasks that use asyncdispatch, it did not work because the same global dispatcher (gDisp) is visible to both tasks (because of the flat memory model).
Does this work on other RTOS (FreeRTOS, Zephyr)? Or have you had similar problems but applied workarounds?
I've used selectors and poll/select on both FreeRTOS and Zephyr. I've only ever done toy examples using async dispatch, however those worked fine.
Though I could see how running multiple threads/tasks with a unified memory space could be problematic. Still gDisp should be a threadvar. Does NuttX provide thread variables? In Zephyr and FreeRTOS you need to enable it. Also Nim has a mechanism to emulate threadvar, though I've never really tested it and forget the Nim flag to enable it.
Thank you for response.
NuttX had TLS functionality, so I enabled it and added to config.nims
switch "tlsemulation", "on"
but it did not work.
I ran it with a console and Telnet login.
As soon as I run the second one, both stop and when I run them again, I get the following error
nsh> hello_nim
hello_nim_async.nim hello_nim
asyncdispatch.nim(2022) waitFor
asyncdispatch.nim(1711) poll
asyncdispatch.nim(1408) runOnce
ioselectors_epoll.nim(379) selectInto
hello_nim_async.nim hello_nim
asyncdispatch.nim(2022) waitFor
asyncdispatch.nim(1711) poll
asyncdispatch.nim(1408) runOnce
ioselectors_epoll.nim(387) selectInto
assertions.nim(287) raiseIOSelectorsError
Error: unhandled exception: Bad file number (code: 9) [IOSelectorsException]
I am currently running the same command (which internally executes one function), but I will try a different command to see what happens.
I tried splitting it into multiple commands (functions), but the Nim definitions seemed to be duplicated when linking.
multiple definition of `parseStandardFormatSpecifier__ pureZstrformat_u56'
multiple definition of `nim_program_result';
With RTOS, it seems difficult to have multiple Nim programs coexist because they are linked to a single binary.
The stacktrace seems to be due to a bad file descriptor and the global gDisp?
It seems that gDisp is placed only one place in the BSS area, probably due to flat binary.
3 .bss 0001efa0 22086000 22086000 00085f20 2**8
ALLOC
$ cat nuttx.map |grep gDisp
.bss.gDisp__pureZasyncdispatch_u2601
0x00000000220a04f4 gDisp__pureZasyncdispatch_u2601
Since NuttX has a function to dynamically load elf-format binaries, it may be necessary to consider using this function.
I have built the command as an ELF binary and verified that it can be run from external storage (still a simple C command that outputs "hello world").
I will experiment with the possibility of using multiple global dispatchers by splitting the program I create in Nim into separate binaries.