Hi, I am relatively new to the Nordic platform and Zephyr RTOS. I am using nRF Connect SDK version 2.6.0 (the VS Code extension on Windows 11) with the nRF52840DK. I was wondering what the best strategy would be for spawning threads that do a small task and then terminate. I have gone through the documentation here and managed to come up with a small demo program to test my understanding. In the program below, the main thread just periodically reads a button state and if high, spawns a new thread. This newly spawned thread just prints a message and returns, which according to the documentation will cause the thread to terminate. The main thread in the meantime sleeps for sometime, within which the thread will probably have terminated. I have flashed it to my nRF42840DK it is working.
I have a few questions:
1. is this the correct approach for spawning short-lived threads? Am I forgetting to do some cleanup? and are there better approaches to use cases such as this ?
2. is k_thread_join() needed here? Because the code seems to work fine without it.
I am a relatively inexperienced dev delving into the world of RTOS programming for the first time so suggestions are really appreciated. Thanks!