public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug nptl/26964] New: pthread_mutex_timedlock returning EAGAIN after futex is locked
@ 2020-11-27 14:31 lamm at linux dot ibm.com
2020-11-27 14:37 ` [Bug nptl/26964] " tuliom at ascii dot art.br
2020-12-01 23:07 ` tuliom at ascii dot art.br
0 siblings, 2 replies; 3+ messages in thread
From: lamm at linux dot ibm.com @ 2020-11-27 14:31 UTC (permalink / raw)
To: glibc-bugs
https://sourceware.org/bugzilla/show_bug.cgi?id=26964
Bug ID: 26964
Summary: pthread_mutex_timedlock returning EAGAIN after futex
is locked
Product: glibc
Version: 2.34
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: nptl
Assignee: unassigned at sourceware dot org
Reporter: lamm at linux dot ibm.com
CC: drepper.fsp at gmail dot com
Target Milestone: ---
This bug was exposed by a PMDK (Persistent Memory Development Kit) testcase
where 25 threads uses the same mutex repetitively competing for it an checking
return error codes. On Fedora Rawhide ppc64le the testcase start receiving
EAGAIN from pthread_mutex_timedlock even without using recursive locks.
To reproduce just create a 50 more thread and send them to lock and unlock
using
pthread_mutex_timedlock. Returning EAGAIN even when the futex is successfully
acquired.
Test code:
#include <errno.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define NANO_PER_ONE 1000000000LL
#define TIMEOUT (NANO_PER_ONE / 1000LL)
#define NUM_THREADS 50
#define WORKER_RUNS 10
static void *
worker(void *arg)
{
for (unsigned run = 0; run < WORKER_RUNS; run++) {
pthread_mutex_t *mtx = (pthread_mutex_t *)arg;
struct timespec abs_time;
clock_gettime(CLOCK_REALTIME, &abs_time);
abs_time.tv_nsec += TIMEOUT;
if (abs_time.tv_nsec >= NANO_PER_ONE) {
abs_time.tv_sec++;
abs_time.tv_nsec -= NANO_PER_ONE;
}
int ret = pthread_mutex_timedlock(mtx, &abs_time);
if (ret == 0)
pthread_mutex_unlock(mtx);
if (ret == EAGAIN) {
printf("EAGAIN returned \n");
return (void *)1;
}
}
return NULL;
}
int
main(void)
{
pthread_t *workers
= (pthread_t *)malloc(NUM_THREADS * sizeof(pthread_t));
pthread_mutex_t mutex;
pthread_mutex_init(&mutex,NULL);
int *thread_ret = NULL, ret = 0;
for (unsigned long run = 0; run < 5; run++) {
for (unsigned i = 0; i < NUM_THREADS; i++) {
pthread_create(&workers[i], NULL, worker,
(void *)&mutex);
}
for (unsigned i = 0; i < NUM_THREADS; i++) {
pthread_join(workers[i], (void **)&thread_ret);
if (thread_ret != NULL)
++ret;
}
}
free(workers);
return ret;
}
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug nptl/26964] pthread_mutex_timedlock returning EAGAIN after futex is locked
2020-11-27 14:31 [Bug nptl/26964] New: pthread_mutex_timedlock returning EAGAIN after futex is locked lamm at linux dot ibm.com
@ 2020-11-27 14:37 ` tuliom at ascii dot art.br
2020-12-01 23:07 ` tuliom at ascii dot art.br
1 sibling, 0 replies; 3+ messages in thread
From: tuliom at ascii dot art.br @ 2020-11-27 14:37 UTC (permalink / raw)
To: glibc-bugs
https://sourceware.org/bugzilla/show_bug.cgi?id=26964
Tulio Magno Quites Machado Filho <tuliom at ascii dot art.br> changed:
What |Removed |Added
----------------------------------------------------------------------------
Version|2.34 |2.33
Ever confirmed|0 |1
CC| |tuliom at ascii dot art.br
Status|UNCONFIRMED |ASSIGNED
Assignee|unassigned at sourceware dot org |lamm at linux dot ibm.com
Last reconfirmed| |2020-11-27
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug nptl/26964] pthread_mutex_timedlock returning EAGAIN after futex is locked
2020-11-27 14:31 [Bug nptl/26964] New: pthread_mutex_timedlock returning EAGAIN after futex is locked lamm at linux dot ibm.com
2020-11-27 14:37 ` [Bug nptl/26964] " tuliom at ascii dot art.br
@ 2020-12-01 23:07 ` tuliom at ascii dot art.br
1 sibling, 0 replies; 3+ messages in thread
From: tuliom at ascii dot art.br @ 2020-12-01 23:07 UTC (permalink / raw)
To: glibc-bugs
https://sourceware.org/bugzilla/show_bug.cgi?id=26964
Tulio Magno Quites Machado Filho <tuliom at ascii dot art.br> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|--- |2.33
Resolution|--- |FIXED
Status|ASSIGNED |RESOLVED
--- Comment #1 from Tulio Magno Quites Machado Filho <tuliom at ascii dot art.br> ---
Fixed with:
commit 61855081017dff30c577855cda882740356b5d98
Author: Lucas A. M. Magalhaes <lamm@linux.ibm.com>
Date: Tue Dec 1 18:05:07 2020 -0300
nptl: Fix __futex_clocklock64 return error check [BZ #26964]
The earlier implementation of this, __lll_clocklock, calls lll_clockwait
that doesn't return the futex syscall error codes. It always tries again
if that fails.
However in the current implementation, when the futex returns EAGAIN,
__futex_clocklock64 will also return EGAIN, even if the futex is taken.
This patch fixes the EAGAIN issue and also adds a check for EINTR. As
futex syscall can return EINTR if the thread is interrupted by a signal.
In this case I'm assuming the function should continue trying to lock as
there is no mention to about it on POSIX. Also add a test for both
scenarios.
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-12-01 23:07 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-27 14:31 [Bug nptl/26964] New: pthread_mutex_timedlock returning EAGAIN after futex is locked lamm at linux dot ibm.com
2020-11-27 14:37 ` [Bug nptl/26964] " tuliom at ascii dot art.br
2020-12-01 23:07 ` tuliom at ascii dot art.br
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).