public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/94996] New: jthread should stop and join the associated thread before being assigned.
@ 2020-05-08 7:45 hotwatermorning at gmail dot com
2020-05-08 8:27 ` [Bug libstdc++/94996] " hotwatermorning at gmail dot com
2020-11-23 13:08 ` redi at gcc dot gnu.org
0 siblings, 2 replies; 3+ messages in thread
From: hotwatermorning at gmail dot com @ 2020-05-08 7:45 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94996
Bug ID: 94996
Summary: jthread should stop and join the associated thread
before being assigned.
Product: gcc
Version: 10.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: hotwatermorning at gmail dot com
Target Milestone: ---
Hi,
A joinable std::jthread should stop and join the associated thread before being
assigned, but it seems that current implementation doesn't.
c.f. https://eel.is/c++draft/thread.jthread.class#thread.jthread.cons-13
c.f. https://github.com/josuttis/jthread/pull/35
Step to reproduce: Build and run this code snippet with gcc-10.1 with
`-std=c++20` option.
#include <cassert>
#include <iostream>
#include <thread>
#include <chrono>
int main()
{
std::cout << "Start a thread." << std::endl;
std::jthread th([](std::stop_token st) {
for( ; st.stop_requested() == false; ) {
std::cout << "." << std::flush;
std::this_thread::sleep_for(std::chrono::milliseconds(300));
}
});
std::stop_token st = th.get_stop_token();
std::this_thread::sleep_for(std::chrono::milliseconds(3000));
th = std::jthread();
// `th` should stop and join the associated thread before being assigned.
assert(st.stop_requested());
std::cout << "Finished." << std::endl;
}
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug libstdc++/94996] jthread should stop and join the associated thread before being assigned.
2020-05-08 7:45 [Bug c++/94996] New: jthread should stop and join the associated thread before being assigned hotwatermorning at gmail dot com
@ 2020-05-08 8:27 ` hotwatermorning at gmail dot com
2020-11-23 13:08 ` redi at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: hotwatermorning at gmail dot com @ 2020-05-08 8:27 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94996
--- Comment #1 from hotwatermorning at gmail dot com ---
Note: The expected behavior is that the associated thread is stopped and joined
at `th = std::jthread();` and the following assertion passes, but the current
implementation aborts at `th = std::jthread();` because the internal _M_thread
data-member is move-assigned while joinable() == true.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug libstdc++/94996] jthread should stop and join the associated thread before being assigned.
2020-05-08 7:45 [Bug c++/94996] New: jthread should stop and join the associated thread before being assigned hotwatermorning at gmail dot com
2020-05-08 8:27 ` [Bug libstdc++/94996] " hotwatermorning at gmail dot com
@ 2020-11-23 13:08 ` redi at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: redi at gcc dot gnu.org @ 2020-11-23 13:08 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94996
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Target Milestone|--- |10.3
Status|UNCONFIRMED |RESOLVED
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Fixed by g:08b4d325711d5c6f68ac29443aba3fd7aa173ac8 and
g:7c44b67d83b34e56a4f65afd70754c5e30280247
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-11-23 13:08 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-08 7:45 [Bug c++/94996] New: jthread should stop and join the associated thread before being assigned hotwatermorning at gmail dot com
2020-05-08 8:27 ` [Bug libstdc++/94996] " hotwatermorning at gmail dot com
2020-11-23 13:08 ` redi at gcc dot gnu.org
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).