This is the mail archive of the
glibc-bugs@sourceware.org
mailing list for the glibc project.
[Bug libc/22622] New: [Bug nptl] pthread_once hangs when init routine throws an exception
- From: "dzhwinter at gmail dot com" <sourceware-bugzilla at sourceware dot org>
- To: glibc-bugs at sourceware dot org
- Date: Sun, 17 Dec 2017 08:10:59 +0000
- Subject: [Bug libc/22622] New: [Bug nptl] pthread_once hangs when init routine throws an exception
- Auto-submitted: auto-generated
https://sourceware.org/bugzilla/show_bug.cgi?id=22622
Bug ID: 22622
Summary: [Bug nptl] pthread_once hangs when init routine throws
an exception
Product: glibc
Version: unspecified
Status: UNCONFIRMED
Severity: critical
Priority: P2
Component: libc
Assignee: unassigned at sourceware dot org
Reporter: dzhwinter at gmail dot com
CC: drepper.fsp at gmail dot com
Target Milestone: ---
This is the same bug with
`Bug 16816 - pthread_once: ABA issue related to the fork generation counter`.
In fact, I find some related case in bugzilla and a fix patch. But it failed in
tst-once5.
A minimum reproduce test http://en.cppreference.com/w/cpp/thread/call_once
```
#include <iostream>
#include <thread>
#include <mutex>
std::once_flag flag1, flag2;
void simple_do_once()
{
std::call_once(flag1, [](){ std::cout << "Simple example: called once\n";
});
}
void may_throw_function(bool do_throw)
{
if (do_throw) {
std::cout << "throw: call_once will retry\n"; // 这会出现多于一次
throw std::exception();
}
std::cout << "Didn't throw, call_once will not attempt again\n"; // 保证一次
}
void do_once(bool do_throw)
{
try {
std::call_once(flag2, may_throw_function, do_throw);
}
catch (...) {
}
}
int main()
{
std::thread st1(simple_do_once);
std::thread st2(simple_do_once);
std::thread st3(simple_do_once);
std::thread st4(simple_do_once);
st1.join();
st2.join();
st3.join();
st4.join();
std::thread t1(do_once, true);
std::thread t2(do_once, true);
std::thread t3(do_once, false);
std::thread t4(do_once, true);
t1.join();
t2.join();
t3.join();
t4.join();
}
```
There is test description in the latest develop branch.
```makefile
# Test expected to fail on most targets (except x86_64) due to bug
# 18435 - pthread_once hangs when init routine throws an exception.
test-xfail-tst-once5 = yes
```
But it failed in x86_64
system: Linux idgsim-gpu-001 4.10.0-40-generic #44~16.04.1-Ubuntu SMP Thu Nov 9
15:37:44 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
glibc: latest branch
commit id 7d38eb38977980efe703eac93645b1af5a5f8a0c
--
You are receiving this mail because:
You are on the CC list for the bug.