From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 159673973049; Fri, 27 Nov 2020 14:31:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 159673973049 From: "lamm at linux dot ibm.com" 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: glibc X-Bugzilla-Component: nptl X-Bugzilla-Version: 2.34 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: lamm at linux dot ibm.com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at sourceware dot org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter cc target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://sourceware.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: glibc-bugs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Glibc-bugs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 27 Nov 2020 14:31:01 -0000 https://sourceware.org/bugzilla/show_bug.cgi?id=3D26964 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 check= ing 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 successful= ly acquired. Test code: #include #include #include #include #include #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 =3D 0; run < WORKER_RUNS; run++) { pthread_mutex_t *mtx =3D (pthread_mutex_t *)arg; struct timespec abs_time; clock_gettime(CLOCK_REALTIME, &abs_time); abs_time.tv_nsec +=3D TIMEOUT; if (abs_time.tv_nsec >=3D NANO_PER_ONE) { abs_time.tv_sec++; abs_time.tv_nsec -=3D NANO_PER_ONE; } int ret =3D pthread_mutex_timedlock(mtx, &abs_time); if (ret =3D=3D 0) pthread_mutex_unlock(mtx); if (ret =3D=3D EAGAIN) { printf("EAGAIN returned \n"); return (void *)1; } } return NULL; } int main(void) { pthread_t *workers =3D (pthread_t *)malloc(NUM_THREADS * sizeof(pthread_t)); pthread_mutex_t mutex; pthread_mutex_init(&mutex,NULL); int *thread_ret =3D NULL, ret =3D 0; for (unsigned long run =3D 0; run < 5; run++) { for (unsigned i =3D 0; i < NUM_THREADS; i++) { pthread_create(&workers[i], NULL, worker, (void *)&mutex); } for (unsigned i =3D 0; i < NUM_THREADS; i++) { pthread_join(workers[i], (void **)&thread_ret); if (thread_ret !=3D NULL) ++ret; } } free(workers); return ret; } --=20 You are receiving this mail because: You are on the CC list for the bug.=