cederom commented on PR #22268: URL: https://github.com/apache/nuttx/pull/22268#issuecomment-7248301086
Thanks for the update. Re-reviewed 24bf49e against 4c73208 (range-diff): - **Use-after-free on free vs. a late `work_queue_run()`: fixed.** `work_queue_free()` now waits for all `nthreads`, and a thread that arrives after the exit request posts `exsem` as its last access and returns `-ESHUTDOWN`. That's true in both the kernel and libc versions, and `nworkers` is gone. `-ESHUTDOWN` is now reliable. - **Workers dying inside the loop:** now documented in the rst and in the header comment of `work_queue_run()`. - **`work_queue_priority_wq()` / `work_queue_setpriority_wq()` on an `init` queue:** documented (`-ESRCH` before the first worker; threads that join later keep their own priority). - **`-EINVAL` / `-EBUSY` consistency:** fixed. The kernel now checks a `run` flag like libc, so both return `-EINVAL` for a queue made by `work_queue_create()`. The `-EBUSY` race with a thread beyond `nthreads` is documented as a usage error, which is fine. One follow-up the new contract creates: - If the caller fails to create one of the `nthreads` threads (`pthread_create()` fails), it can no longer free the queue: `work_queue_free()` waits for a thread that will never come. The only escape is to call `work_queue_run()` once per missing thread from some other thread after `work_queue_free()` has started, which is not obvious. Please either document the error-path recipe or allow giving up unused slots, e.g. let `work_queue_free()` count slots that were never taken when the caller says so, or add a small `work_queue_run()`-like "abandon slot" call. Documenting it is enough for me. Still open from before, not blocking: a test that frees the queue while one of the `nthreads` threads has not started yet (apps #4140?), plus SMP and CMake coverage. Would it be possible to create? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
