public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "klemensbaum at gmail dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/65393] New: std::thread shared_ptr inefficiency Date: Wed, 11 Mar 2015 19:00:00 -0000 [thread overview] Message-ID: <bug-65393-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65393 Bug ID: 65393 Summary: std::thread shared_ptr inefficiency Product: gcc Version: unknown Status: UNCONFIRMED Severity: enhancement Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: klemensbaum at gmail dot com The std::thread implementation passes around shared_ptr instances by value in multiple places where they could be moved: 1) in the function void thread::_M_start_thread(__shared_base_type __b) the line _M_start_thread(__b, nullptr); could be changed to _M_start_thread(std::move(__b), nullptr); or alternatively take __shared_base_type by "universal reference" and forward it into the other _M_start_thread overload. 2) in the function void thread::_M_start_thread(__shared_base_type __b, void (*)()) the lines __b->_M_this_ptr = __b; int __e = __gthread_create(&_M_id._M_thread, &execute_native_thread_routine, __b.get()); could be changed to auto __p = __b.get(); __b->_M_this_ptr = std::move(__b); int __e = __gthread_create(&_M_id._M_thread, &execute_native_thread_routine, __p); 3) Finally, the use of shared_ptr seems wholly unnecessarily. This can likely be implemented more cleanly with unique_ptr, and more efficiently, since it avoids the extra heap space for the reference count and all of the atomic ops.
next reply other threads:[~2015-03-11 19:00 UTC|newest] Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top 2015-03-11 19:00 klemensbaum at gmail dot com [this message] 2015-03-11 19:14 ` [Bug libstdc++/65393] " redi at gcc dot gnu.org 2015-06-16 17:54 ` redi at gcc dot gnu.org 2015-06-22 15:54 ` redi at gcc dot gnu.org 2015-09-29 12:56 ` redi at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-65393-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).