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:
@@ -91,7 +91,7 @@ static inline void esc_ctl (unsigned char *str, int len) {
|
||||
}
|
||||
|
||||
int escape_str (unsigned char *dst, const unsigned char *src, int bufsize) {
|
||||
static int utf_sw = 0;
|
||||
static __thread int utf_sw = 0;
|
||||
int n;
|
||||
|
||||
if (utf_sw == 0) {
|
||||
|
||||
Reference in New Issue
Block a user