public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/65393] New: std::thread shared_ptr inefficiency
@ 2015-03-11 19:00 klemensbaum at gmail dot com
  2015-03-11 19:14 ` [Bug libstdc++/65393] " redi at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: klemensbaum at gmail dot com @ 2015-03-11 19:00 UTC (permalink / raw)
  To: gcc-bugs

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.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-09-29 12:56 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-11 19:00 [Bug libstdc++/65393] New: std::thread shared_ptr inefficiency klemensbaum at gmail dot com
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

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).