library: ensure thread safety for all static variables

Even though we we had to abandon the master branch top
multi-thread effort and even though the newlib version
of a multi-threaded top provides no real benefit, that
whole exercise was not wasted. Rather, it has revealed
some deficiencies in our library which this addresses.

If two or more threads in the same address space tried
to access the same api simultaneously, there is a good
chance some function-local static variables will yield
some of those renowned unpredictable results. So, this
patch protects them with the '__thread' storage class.

Reference(s):
https://www.freelists.org/post/procps/a-few-more-patches,7

Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
Jim Warner
2021-09-28 00:00:00 -05:00
committed by Craig Small
parent 69978e3650
commit 23cfb71366
10 changed files with 28 additions and 28 deletions

View File

@@ -990,7 +990,7 @@ PROCPS_EXPORT struct stat_result *procps_stat_get (
struct stat_info *info,
enum stat_item item)
{
static time_t sav_secs;
static __thread time_t sav_secs;
time_t cur_secs;
errno = EINVAL;