From 9fe28f703d44ff1ddecdca945bfb5fc87de5e8ad Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Mon, 7 Mar 2011 18:09:24 -0500 Subject: [PATCH] fix off-by-one error in sem_(timed)wait (using old sem value instead of new) --- src/thread/sem_timedwait.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/thread/sem_timedwait.c b/src/thread/sem_timedwait.c index e6604364..e6c2495a 100644 --- a/src/thread/sem_timedwait.c +++ b/src/thread/sem_timedwait.c @@ -7,7 +7,7 @@ int sem_timedwait(sem_t *sem, const struct timespec *at) for (;;) { if (a_fetch_add(sem->__val, -1) > 0) return 0; - val = a_fetch_add(sem->__val, 1); + val = a_fetch_add(sem->__val, 1)+1; CANCELPT_BEGIN; if (val <= 0 && __timedwait(sem->__val, val, CLOCK_REALTIME, at, 0) == ETIMEDOUT) { errno = ETIMEDOUT; -- GitLab