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

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).