http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60662
Bug ID: 60662
Summary: simple use of call_once throws a system_error
exception, but not if sleep_for is called beforehand
Product: gcc
Version: 4.8.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: sambler at alumni dot nd.edu
Created attachment 32457
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=32457&action=edit
preprocessed source code, lengthy due to standard C++ headers
file test_unique.cc (misnomer from original guess at cause of problem):
#include
#include
#include
using namespace std;
int main() {
once_flag once;
// this_thread::sleep_for(chrono::milliseconds(1));
call_once(once, [](){});
return 0;
}
file buildcc11:
g++ -std=c++11 -Wall -Wextra -save-temps $1.cc -lpthread -o $1
execution:
$ ./buildcc11 test_unique
$ ./test_unique
terminate called after throwing an instance of 'std::system_error'
what(): Unknown error -1
Aborted (core dumped)
$
whereas after uncommenting the sleep_for line:
$ ./buildcc11 test_unique
$ ./test_unique
$
BEGIN PARENTHETICAL NOTE:
Initially discovered in a more complicated context, this problem was quite
robust w.r.t. a number of changes such as for simplification. For example,
the following less artificial use of call_once has the same problem (file
test_unique_2.cc):
#include
#include
#include
#include
using namespace std;
once_flag once;
int n = 0;
void f(int n_arg) {
n = n_arg;
}
int main() {
// this_thread::sleep_for(chrono::milliseconds(1));
int m = 1;
call_once(once, f, m++);
call_once(once, f, m++);
call_once(once, f, m++);
cout << "n " << n << endl;
return 0;
}
$ ./buildcc11 test_unique_2
$ ./test_unique_2
terminate called after throwing an instance of 'std::system_error'
what(): Unknown error -1
Aborted (core dumped)
$
whereas after uncommenting the sleep_for:
$ ./buildcc11 test_unique_2
$ ./test_unique_2
n 1
$
END PARENTHETICAL NOTE
compiler & system info:
$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.8/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro
4.8.1-10ubuntu9' --with-bugurl=file:///usr/share/doc/gcc-4.8/README.Bugs
--enable-languages=c,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr
--program-suffix=-4.8 --enable-shared --enable-linker-build-id
--libexecdir=/usr/lib --without-included-gettext --enable-threads=posix
--with-gxx-include-dir=/usr/include/c++/4.8 --libdir=/usr/lib --enable-nls
--with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug
--enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin
--with-system-zlib --disable-browser-plugin --enable-java-awt=gtk
--enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-4.8-amd64/jre
--enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-4.8-amd64
--with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-4.8-amd64
--with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar
--enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686
--with-abi=m64 --with-multilib-list=m32,m64,mx32 --with-tune=generic
--enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu
--target=x86_64-linux-gnu
Thread model: posix
gcc version 4.8.1 (Ubuntu/Linaro 4.8.1-10ubuntu9)
lenovo ThinkPad SL510 2x Intel Core 2 Duo T6670 2.20 GHz, 8 GB RAM, Ubuntu
13.10 (Lubuntu), Linux 3.11.0-18-generic (x86_64).
preprocessed file from ./buildcc11 test_unique with commented-out sleep_for not
included b/c of 64K char limit on this field; instead attached.
Thanks!