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:
@@ -325,7 +325,7 @@ static int ctty_name(char *restrict const buf, int pid) {
|
||||
|
||||
/* number --> name */
|
||||
unsigned dev_to_tty(char *restrict ret, unsigned chop, dev_t dev_t_dev, int pid, unsigned int flags) {
|
||||
static char buf[TTY_NAME_SIZE];
|
||||
static __thread char buf[TTY_NAME_SIZE];
|
||||
char *restrict tmp = buf;
|
||||
unsigned dev = dev_t_dev;
|
||||
unsigned i = 0;
|
||||
|
||||
Reference in New Issue
Block a user