From 7b34f32fc4b91377bd0521c5ddc893d8f524eb6d Mon Sep 17 00:00:00 2001 From: Justine Tunney Date: Fri, 17 Jun 2022 04:17:21 -0700 Subject: [PATCH] Use exponential backoff in mutexes --- libc/intrin/pthread_mutex_lock.c | 3 ++- libc/sysv/calls/sys_sched_yield.s | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/libc/intrin/pthread_mutex_lock.c b/libc/intrin/pthread_mutex_lock.c index 049cb8200..c52355b3a 100644 --- a/libc/intrin/pthread_mutex_lock.c +++ b/libc/intrin/pthread_mutex_lock.c @@ -29,7 +29,8 @@ * @return 0 on success, or error number on failure */ int pthread_mutex_lock(pthread_mutex_t *mutex) { - int i, me, owner, tries; + volatile int i; + int me, owner, tries; for (tries = 0, me = gettid();;) { owner = atomic_load_explicit(&mutex->lock, memory_order_relaxed); if (!owner && atomic_compare_exchange_weak_explicit( diff --git a/libc/sysv/calls/sys_sched_yield.s b/libc/sysv/calls/sys_sched_yield.s index f3d91b392..9aa933153 100644 --- a/libc/sysv/calls/sys_sched_yield.s +++ b/libc/sysv/calls/sys_sched_yield.s @@ -1,2 +1,2 @@ .include "o/libc/sysv/macros.internal.inc" -.scall sys_sched_yield,0x15e12a14b103c018,globl,hidden +.scall sys_sched_yield,0x15e12a14bffff018,globl,hidden