| 68 | { } |
| 69 | |
| 70 | void runInThread() |
| 71 | { |
| 72 | *tid_ = muduo::CurrentThread::tid(); |
| 73 | tid_ = NULL; |
| 74 | latch_->countDown(); |
| 75 | latch_ = NULL; |
| 76 | |
| 77 | muduo::CurrentThread::t_threadName = name_.empty() ? "muduoThread" : name_.c_str(); |
| 78 | ::prctl(PR_SET_NAME, muduo::CurrentThread::t_threadName); |
| 79 | try |
| 80 | { |
| 81 | func_(); |
| 82 | muduo::CurrentThread::t_threadName = "finished"; |
| 83 | } |
| 84 | catch (const Exception& ex) |
| 85 | { |
| 86 | muduo::CurrentThread::t_threadName = "crashed"; |
| 87 | fprintf(stderr, "exception caught in Thread %s\n", name_.c_str()); |
| 88 | fprintf(stderr, "reason: %s\n", ex.what()); |
| 89 | fprintf(stderr, "stack trace: %s\n", ex.stackTrace()); |
| 90 | abort(); |
| 91 | } |
| 92 | catch (const std::exception& ex) |
| 93 | { |
| 94 | muduo::CurrentThread::t_threadName = "crashed"; |
| 95 | fprintf(stderr, "exception caught in Thread %s\n", name_.c_str()); |
| 96 | fprintf(stderr, "reason: %s\n", ex.what()); |
| 97 | abort(); |
| 98 | } |
| 99 | catch (...) |
| 100 | { |
| 101 | muduo::CurrentThread::t_threadName = "crashed"; |
| 102 | fprintf(stderr, "unknown exception caught in Thread %s\n", name_.c_str()); |
| 103 | throw; // rethrow |
| 104 | } |
| 105 | } |
| 106 | }; |
| 107 | |
| 108 | void* startThread(void* obj) |
no test coverage detected