[Bug 1876958] Re: Ubuntu-specific pthread issue
David Rogers
wantye at gmail.com
Wed May 6 17:56:14 UTC 2020
Update: this does not involve threads (see new minimal version below).
Also, adding -O2 to the above version (with threading) gives no output,
but creates a SEGV with the version below. Finally, the bug occurs at
compile-time, not link time, since the object file (".o") created from
this also errors when run on CentOS.
#include <functional>
#include <stdio.h>
struct run {
const std::function<void()> &fn;
run(const std::function<void()> &fn_) : fn(fn_) {}
void operator()() {
fn();
}
};
int main() {
auto fn1 = [](){ printf("fn1\n"); };
auto r1 = run(fn1);
auto fn2 = [](){ printf("fn2\n"); };
auto r2 = run(fn2);
r1();
r2();
}
--
You received this bug notification because you are a member of Ubuntu
Foundations Bugs, which is subscribed to gcc-defaults in Ubuntu.
https://bugs.launchpad.net/bugs/1876958
Title:
Ubuntu-specific pthread issue
Status in gcc-defaults package in Ubuntu:
New
Bug description:
The following c++11 program works properly (prints fn1 and fn2) on
every system and compiler I have checked except for Ubuntu - where it
prints (fn2 and fn2). This happens on both laptop and server installs
of Ubuntu 18.04.
All system gcc packages on my Ubuntu 18.04 system show the same (incorrect) output:
g++-5 (Ubuntu 5.5.0-12ubuntu1) 5.5.0 20171010
g++-6 (Ubuntu 6.5.0-2ubuntu1~18.04) 6.5.0 20181026
g++-7 (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
g++-8 (Ubuntu 8.3.0-26ubuntu1~18.04) 8.3.0
Notes:
- Re-compiling gcc from source eliminates the problem.
- I have not checked any Ubuntu versions other than 18.04.
Off-topic note:
- this may be a [libpthread bug](https://bugs.launchpad.net/ubuntu/+source/libpthread-stubs/)?
/* Minimal bug-reproducer for gcc on ubuntu */
#include <functional>
#include <thread>
#include <stdio.h>
struct run {
const std::function<void()> &fn;
run(const std::function<void()> &fn_) : fn(fn_) {}
void operator()() {
fn();
}
};
int main() {
auto fn1 = [](){ printf("fn1\n"); };
auto r1 = run(fn1);
auto fn2 = [](){ printf("fn2\n"); };
auto r2 = run(fn2);
std::thread t1( r1 );
std::thread t2( r2 );
t1.join();
t2.join();
}
To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/gcc-defaults/+bug/1876958/+subscriptions
More information about the foundations-bugs
mailing list