casaroli opened a new pull request, #22581: URL: https://github.com/apache/nuttx/pull/22581
## Summary Since #21834, `PTHREAD_PROCESS_PRIVATE` is 1 and `PTHREAD_PROCESS_SHARED` is 2. `pthread_spin_init()` accepts only these two values (the check came with #21693, when the values were 0 and 1), so `pthread_spin_init(&lock, 0)` now returns `EINVAL`. Programs written for Linux often give a literal 0 as the private value: in glibc `PTHREAD_PROCESS_PRIVATE` is 0, and `pthread_spin_init()` does not check `pshared` at all. The spin lock is an atomic variable and works the same in private and in shared memory, so `pshared` does not change the lock. `pthread_spin_init()` now does not check `pshared`, as glibc and as NuttX before #21693. A NULL lock still gives `EINVAL`. The `_setpshared()` functions of the attribute objects do not change: they still return `EINVAL` for a value that is not `PTHREAD_PROCESS_PRIVATE` or `PTHREAD_PROCESS_SHARED`, as in glibc. ## Impact `pthread_spin_init()` accepts every `pshared` value; before, all values other than 1 and 2 gave `EINVAL`. A program that worked before still works. No change to the values of `PTHREAD_PROCESS_*`, no API, ABI or Kconfig change. The change is in libc C code without `#ifdef` (built with `CONFIG_PTHREAD_SPINLOCKS`): the same in flat, protected and kernel builds and on all architectures. Documentation/ has no text on the `pshared` argument of `pthread_spin_init()`. ## Testing New case `test_nuttx_pthread_test22` in `cmocka_pthread_test` (apache/nuttx-apps#NNNN): `pthread_spin_init()` with `PTHREAD_PROCESS_PRIVATE`, `PTHREAD_PROCESS_SHARED` and 0, then lock, trylock (`EBUSY`), unlock, destroy. | | master | this PR | |---|---|---| | qemu-armv8a:nsh (flat, CI image gcc 12.3, QEMU TCG) | `test_nuttx_pthread_test22` FAILED (`22 != 0`: `EINVAL` for 0) | 9 passed | | qemu-intel64:knsh_romfs (kernel, KVM) | `test_nuttx_pthread_test22` FAILED (`22 != 0`) | 9 passed | Builds with `-Werror` in the CI image: rv-virt:citest (with the new case); qemu-armv8a:knsh and rv-virt:knsh64 (kernel), rv-virt:pnsh64 (protected), qemu-armv8a:nsh with `CONFIG_PTHREAD_SPINLOCKS`; qemu-armv8a:nsh with `cmocka_pthread_test` and without `CONFIG_PTHREAD_SPINLOCKS`. -- 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]
