This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH, v3] std::thread ctor passes function pointer by reference to _M_make_shared_data.


I noticed that there were no tests for std::thread's first ctor taking
just a _Callable so I tried the following:

void f() {}

int main() {
  std::thread t(f);
  t.join();
}

but it failed. Segmentation fault in _M_run().

Turns out, the std::thread(_Callable) ctor is called with _Callable =
void(*)() (i.e. pointer by value), however when passed to
_M_make_shared_data(_Callable&&), _Callable there becomes void(*&)()
so _Impl ends up holding a reference to the local temporary pointer
from the ctor. This blows up when _M_run tries to execute _M_func().

By explicitly specifying the template argument to the
_M_make_shared_data call, pointers are passed by value and
rvalue/lvalue-refs are still forwarded correctly.

Tested x86_64, ok for trunk?

Chris

Attachment: thread_patch.txt
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]