Was passing a reference to a local stringstream into
Thread::create, not realising that it was taking a char*
reference instead of a copy. Result was garbage (or usually,
all threads having the name of the last one created)
Signed-off-by: John Spray <john.spray@redhat.com>
if (r != 0) {
return r;
} else {
- std::ostringstream thread_name;
- thread_name << "mgr." << module_name;
dout(4) << "Starting thread for " << module_name << dendl;
- modules[module_name]->thread.create(thread_name.str().c_str());
+ // Giving Thread the module's module_name member as its
+ // char* thread name: thread must not outlive module class lifetime.
+ modules[module_name]->thread.create(
+ modules[module_name]->get_name().c_str());
return 0;
}
modules.erase(module_name);
return r;
} else {
- std::ostringstream thread_name;
- thread_name << "mgr." << module_name;
dout(4) << "Starting thread for " << module_name << dendl;
- modules[module_name]->thread.create(thread_name.str().c_str());
+ // Giving Thread the module's module_name member as its
+ // char* thread name: thread must not outlive module class lifetime.
+ modules[module_name]->thread.create(
+ modules[module_name]->get_name().c_str());
return 0;
}
}