public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "zoltan at epochcapital dot com.au" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug libstdc++/54562] New: mutex and condition variable timers
Date: Thu, 13 Sep 2012 02:19:00 -0000	[thread overview]
Message-ID: <bug-54562-4@http.gcc.gnu.org/bugzilla/> (raw)

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54562

             Bug #: 54562
           Summary: mutex and condition variable timers
    Classification: Unclassified
           Product: gcc
           Version: 4.7.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: zoltan@epochcapital.com.au


Created attachment 28182
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=28182
std::timed_mutex::try_lock_for test

Hello,

1., When using std::timed_mutex::try_lock_for() with high precision timers
enabled on Linux the method will return immediately, rather than after the
given time duration has elapsed. This is because it uses the CLOCK_MONOTONIC
clock (if available on the platform) to calculate the absolute time when it
needs to return, which is incorrect as the POSIX pthread_mutex_timedlock() call
uses the CLOCK_REALTIME clock, and on my platform the monotonic clock is way
behind the real time clock. 

Please see the attached cpptest.cpp file to reproduce the problem:
$ g++-4.7.1 -std=gnu++11 cpptest.cpp -o cpptest
$ ./cpptest 
mutex locked
delay: 0

It should have displayed "delay: 3" instead.

2., std::condition_variable uses the std::chrono::system_clock for timed waits,
I suggest changing that to std::chrono::high_resolution_clock which has the
same precision as the POSIX pthread_cond_timedwait() function.

My platform:
# uname -a
Linux epcau-srv-dev 2.6.33.7-rt29-0.5-rt #1 SMP PREEMPT RT 2010-08-25 19:40:23
+0200 x86_64 x86_64 x86_64 GNU/Linux
# g++-4.7.1 -v
Reading specs from /opt/epoch/lib64/gcc/x86_64-suse-linux/4.7.1/specs
COLLECT_GCC=g++-4.7.1
COLLECT_LTO_WRAPPER=/opt/epoch/lib64/gcc/x86_64-suse-linux/4.7.1/lto-wrapper
Target: x86_64-suse-linux
Configured with: ../gcc-4.7.1-mutex/configure --build=x86_64-suse-linux
--prefix=/opt/epoch --libdir=/opt/epoch/lib64 --libexecdir=/opt/epoch/lib64
--with-slibdir=/opt/epoch/lib64/gcc/x86_64-suse-linux/4.7.1/libgcc/lib64
--with-gxx-include-dir=/opt/epoch/include/c++/4.7.1 --program-suffix=-4.7.1
--enable-version-specific-runtime-libs --enable-languages=c++ --disable-nls
--disable-libssp --enable-__cxa_atexit --with-system-zlib --enable-gold
--with-plugin-ld=/usr/bin/gold --enable-lto --enable-libstdcxx-time=rt
--enable-linux-futex --enable-libstdcxx-threads --enable-libstdcxx-debug
--enable-libstdcxx-allocator=new
Thread model: posix
gcc version 4.7.1 (GCC)


             reply	other threads:[~2012-09-13  2:19 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-13  2:19 zoltan at epochcapital dot com.au [this message]
2012-09-13  2:24 ` [Bug libstdc++/54562] " zoltan at epochcapital dot com.au
2012-10-08 19:55 ` redi at gcc dot gnu.org
2012-10-08 22:11 ` zoltan at epochcapital dot com.au
2013-11-11 13:33 ` redi at gcc dot gnu.org
2013-11-11 13:35 ` redi at gcc dot gnu.org

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-54562-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.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).