public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug nptl/26801] New: pthread_mutex_clocklock with CLOCK_MONOTONIC can fail on PI futexs
@ 2020-10-28 13:54 yeatesrichardr at johndeere dot com
  2020-10-28 13:59 ` [Bug nptl/26801] " yeatesrichardr at johndeere dot com
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: yeatesrichardr at johndeere dot com @ 2020-10-28 13:54 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=26801

            Bug ID: 26801
           Summary: pthread_mutex_clocklock with CLOCK_MONOTONIC can fail
                    on PI futexs
           Product: glibc
           Version: 2.30
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: nptl
          Assignee: unassigned at sourceware dot org
          Reporter: yeatesrichardr at johndeere dot com
                CC: drepper.fsp at gmail dot com
  Target Milestone: ---

Created attachment 12925
  --> https://sourceware.org/bugzilla/attachment.cgi?id=12925&action=edit
Test program showing early return from pthread_mutex_clocklock()

When a pthread mutex is ROBUST_NP, ERRORCHECK, and PRIO_INHERIT (other
combination may fall into this same category) and pthread_mutex_clocklock() is
used with CLOCK_MONOTONIC, the call will return immediately with ETIMEDOUT if
the mutex is already taken at the time of the call.

This was tested with glibc 2.30, but still appears to be present in the latest
source code. The root cause is at line 381 of pthread_mutex_timedlock.c:
   int e = futex_lock_pi64 (&mutex->__data.__lock, abstime, private);
Here, the CLOCK_MONOTONIC abstime is being passed to futex_lock_pi64 which
requires a CLOCK_REALTIME abstime. Of course, a CLOCK_MONOTONIC looks a lot
"earlier" than a CLOCK_REALTIME, so it times out immediately.

It's not sufficient to convert from CLOCK_MONOTONIC to CLOCK_REALTIME since
that would violate the assumption one is using, that changes to the wall clock
time won't interfere with CLOCK_MONOTONIC timed waits.

This was tested with kernel 5.4.47.

Example program is attached.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-11-25 15:31 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-28 13:54 [Bug nptl/26801] New: pthread_mutex_clocklock with CLOCK_MONOTONIC can fail on PI futexs yeatesrichardr at johndeere dot com
2020-10-28 13:59 ` [Bug nptl/26801] " yeatesrichardr at johndeere dot com
2020-10-28 14:01 ` [Bug nptl/26801] pthread_mutex_clocklock with CLOCK_MONOTONIC can fail on PI mutexes yeatesrichardr at johndeere dot com
2020-10-28 17:33 ` yeatesrichardr at johndeere dot com
2020-10-28 20:02 ` adhemerval.zanella at linaro dot org
2020-11-25 15:31 ` adhemerval.zanella at linaro dot org

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