| 31 | namespace atc = apache::thrift::concurrency; |
| 32 | |
| 33 | void ThriftThread::start() { |
| 34 | Promise<atc::Thread::id_t> promise; |
| 35 | // As noted in https://en.cppreference.com/w/cpp/utility/functional/bind, std::bind |
| 36 | // makes a copy of its arguments, notably runnable() which is a shared_ptr. That ensures |
| 37 | // it will live as long as the thread despite passing to RunRunnable by reference. |
| 38 | Status status = impala::Thread::Create(group_, name_, |
| 39 | bind(&ThriftThread::RunRunnable, this, runnable(), &promise), &impala_thread_); |
| 40 | |
| 41 | // Thread creation failed. Thrift expects an exception in this case. See |
| 42 | // the implementation of atc::PosixThreadFactory.cpp or atc::BoostThreadFactory.cpp. |
| 43 | if (!status.ok()) { |
| 44 | throw atc::SystemResourceException( |
| 45 | Substitute("Thread::Create() failed: $0", status.GetDetail())); |
| 46 | } |
| 47 | |
| 48 | // Blocks until the thread id has been set |
| 49 | tid_ = promise.Get(); |
| 50 | } |
| 51 | |
| 52 | atc::Thread::id_t ThriftThread::getId() { |
| 53 | return tid_; |