From 3bbc3c84094333f9097e04461ceef71d4152ad42 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Tue, 15 Feb 2022 11:26:03 +0100 Subject: Rewait if sem_wait is interrupted (pthread_mutex_lock cannot be interrupted) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- libar2simplified_hash.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libar2simplified_hash.c b/libar2simplified_hash.c index b21ef5b..e5765f5 100644 --- a/libar2simplified_hash.c +++ b/libar2simplified_hash.c @@ -85,6 +85,8 @@ thread_loop(void *data_) for (;;) { if (sem_wait(&data->semaphore)) { + if (errno == EINTR) + continue; data->error = errno; return NULL; } @@ -299,8 +301,11 @@ await_threads(size_t *indices, size_t n, size_t require, struct libar2_context * for (;;) { if (ret < require) { - if (sem_wait(&data->semaphore)) + if (sem_wait(&data->semaphore)) { + if (errno == EINTR) + continue; return 0; + } } else if (sem_trywait(&data->semaphore)) { if (errno == EAGAIN) break; -- cgit v1.2.3-70-g09d2