RIOT
RIOT copied to clipboard
sys/newlib_syscalls_default: fix race condition in __sinit()
Contribution description
This eagerly calls __sinit() instead of lazy initialization upon the first call to stdio (e.g. puts(), printf()). The issue is that without locking (as is currently the case for all RIOT platforms but ESP) two concurrent "first calls" may result in concurrent initialization of the same structure and data corruption.
Testing procedure
Have two threads concurrently use stdio and the boot message disabled. This may result in data corruptions and crashes.
See https://github.com/RIOT-OS/RIOT/issues/20067 for details on a reproducible crashing app.
Issues/PRs references
Fixes https://github.com/RIOT-OS/RIOT/issues/20067
@mchesser: Could you give this a try?
I'm aware that it still is a pain in the ass that RIOT doesn't support (at least optional) reentrancy for platforms other than ESP. That is in issue that stills needs to be addressed.
However, even people desperate for saving RAM don't like crashes, and this hopefully makes the concurrent use of stdio crash-free.
Murdock results
:heavy_check_mark: PASSED
375aed13e6d90c1b7e0fc7263f04ff12a84dc29e sys/newlib_syscalls_default: fix race condition in __sinit()
| Success | Failures | Total | Runtime |
|---|---|---|---|
| 142848 | 0 | 142848 | 02h:14m:59s |
Artifacts
OK, full CI run with tests passed. I guess this is OK to merge.
Note: The CI run failed twice before due to:
- No USB connection to a
samr21-xpro. (I'd say that is safe to ignore, either the USB cable was disconnected, flaky, or the issue is with the eDBG and not with the firmware on the MCU.) - A test on
nativefailed because some wake up was too slow. This could be due to load, or due to the general flakiness ofnative.
Thx :)