This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libstdc++/54562] New: mutex and condition variable timers
- From: "zoltan at epochcapital dot com.au" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 13 Sep 2012 02:18:44 +0000
- Subject: [Bug libstdc++/54562] New: mutex and condition variable timers
- Auto-submitted: auto-generated
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)