69 {
70 m_th = 0;
71 if (destroyed) {
72 if (pthread_create(&m_th, NULL, PThread::create_destroy<WORKER>,
73 (void*)worker) != 0) {
74 m_th = 0;
75 }
76 } else {
77 if (pthread_create(&m_th, NULL, PThread::create<WORKER>,
78 (void*)worker) != 0) {
79 m_th = 0;
80 }
81 }
82#if (defined(__GLIBC__) && defined(__GNU_SOURCE) && __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 12)
83 if ((m_th != 0) && (thread_name != "")) {
84 try {
85 if (pthread_setname_np(m_th, thread_name.c_str()) != 0) {
86 LogFile::info("Failed to set process name %d", m_th);
87 }
88 char comp_name[64];
89 pthread_getname_np(m_th, comp_name, 16);
90 if (strcmp(thread_name.c_str(), comp_name) != 0) {
91 prctl(PR_SET_NAME, thread_name.c_str());
92 }
93 } catch (const std::exception& e) {
94 LogFile::error(e.what());
95 }
96 }
97#endif
98 if (detached) {
99 detach();
100 m_th = 0;
101 }
102 }