public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "lamm at linux dot ibm.com" <sourceware-bugzilla@sourceware.org>
To: glibc-bugs@sourceware.org
Subject: [Bug nptl/26964] New: pthread_mutex_timedlock returning EAGAIN after futex is locked
Date: Fri, 27 Nov 2020 14:31:00 +0000	[thread overview]
Message-ID: <bug-26964-131@http.sourceware.org/bugzilla/> (raw)

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.

             reply	other threads:[~2020-11-27 14:31 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-27 14:31 lamm at linux dot ibm.com [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-26964-131@http.sourceware.org/bugzilla/ \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=glibc-bugs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).