diff --git a/mainapp.cpp b/mainapp.cpp index 9c59358..e9e3891 100644 --- a/mainapp.cpp +++ b/mainapp.cpp @@ -130,7 +130,7 @@ void MainApp::start() { std::shared_ptr t(new ThreadData(i, subscriptionStore)); std::thread thread(do_thread_work, t.get()); - t->thread = std::move(thread); + t->moveThreadHere(std::move(thread)); threads.push_back(t); } diff --git a/threaddata.cpp b/threaddata.cpp index 99d137b..806df4e 100644 --- a/threaddata.cpp +++ b/threaddata.cpp @@ -1,4 +1,6 @@ #include "threaddata.h" +#include +#include ThreadData::ThreadData(int threadnr, std::shared_ptr &subscriptionStore) : subscriptionStore(subscriptionStore), @@ -14,6 +16,17 @@ ThreadData::ThreadData(int threadnr, std::shared_ptr &subscri check(epoll_ctl(epollfd, EPOLL_CTL_ADD, event_fd, &ev)); } +void ThreadData::moveThreadHere(std::thread &&thread) +{ + this->thread = std::move(thread); + + pthread_t native = this->thread.native_handle(); + std::ostringstream threadName; + threadName << "FlashMQ T " << threadnr; + threadName.flush(); + pthread_setname_np(native, threadName.str().c_str()); +} + void ThreadData::quit() { running = false; diff --git a/threaddata.h b/threaddata.h index 00d42d0..bfa1acf 100644 --- a/threaddata.h +++ b/threaddata.h @@ -36,6 +36,7 @@ public: ThreadData(int threadnr, std::shared_ptr &subscriptionStore); + void moveThreadHere(std::thread &&thread); void quit(); void giveClient(Client_p client); Client_p getClient(int fd);