Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
|
TODO: Consider allowing fragment IDs as category parameters. More...
#include <thread.h>
Public Member Functions | |
template<class F > | |
Thread (const std::string &category, const std::string &name, const F &f) | |
template<class F , class A1 > | |
Thread (const std::string &category, const std::string &name, const F &f, const A1 &a1) | |
template<class F , class A1 , class A2 > | |
Thread (const std::string &category, const std::string &name, const F &f, const A1 &a1, const A2 &a2) | |
template<class F , class A1 , class A2 , class A3 > | |
Thread (const std::string &category, const std::string &name, const F &f, const A1 &a1, const A2 &a2, const A3 &a3) | |
template<class F , class A1 , class A2 , class A3 , class A4 > | |
Thread (const std::string &category, const std::string &name, const F &f, const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4) | |
template<class F , class A1 , class A2 , class A3 , class A4 , class A5 > | |
Thread (const std::string &category, const std::string &name, const F &f, const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4, const A5 &a5) | |
void | Join () const |
int64_t | tid () const |
Static Public Attributes | |
static const int64_t | INVALID_THREAD_ID = -1 |
Private Types | |
typedef boost::function< void()> | ThreadFunctor |
Function object that wraps the user-supplied function to run in a separate thread. More... | |
Private Member Functions | |
void | StartThread (const ThreadFunctor &functor) |
Static Private Member Functions | |
static void | SuperviseThread (const std::string &name, const std::string &category, ThreadFunctor functor, Promise< int64_t > *thread_started) |
Private Attributes | |
boost::scoped_ptr< boost::thread > | thread_ |
The actual thread object that runs the user's method via SuperviseThread(). More... | |
const std::string | category_ |
Name and category for this thread. More... | |
const std::string | name_ |
int64_t | tid_ |
Static Private Attributes | |
static const int64_t | UNINITIALISED_THREAD_ID = -2 |
TODO: Consider allowing fragment IDs as category parameters.
Thin wrapper around boost::thread that can register itself with the singleton ThreadMgr (a private class implemented in thread.cc entirely, which tracks all live threads so that they may be monitored via the debug webpages). This class has a limited subset of boost::thread's API. Construction is almost the same, but clients must supply a category and a name for each thread so that they can be identified in the debug web UI. Otherwise, Join() is the only supported method from boost::thread. Each Thread object knows its operating system thread ID (tid), which can be used to attach debuggers to specific threads, to retrieve resource-usage statistics from the operating system, and to assign threads to resource control groups.
|
private |
|
inline |
This constructor pattern mimics that in boost::thread. There is one constructor for each number of arguments that the thread function accepts. To extend the set of acceptable signatures, add another constructor with <class F, class A1.... class An>. In general:
Definition at line 61 of file thread.h.
References StartThread().
|
inline |
Definition at line 67 of file thread.h.
References StartThread().
|
inline |
Definition at line 73 of file thread.h.
References StartThread().
|
inline |
Definition at line 80 of file thread.h.
References StartThread().
|
inline |
Definition at line 87 of file thread.h.
References StartThread().
|
inline |
Definition at line 94 of file thread.h.
References StartThread().
|
inline |
Blocks until this thread finishes execution. Once this method returns, the thread will be unregistered with the ThreadMgr and will not appear in the debug UI.
Definition at line 102 of file thread.h.
References thread_.
Referenced by ImpalaThreadStarter(), and impala::ThreadGroup::JoinAll().
|
private |
Starts the thread running SuperviseThread(), and returns once that thread has initialised and its TID read. Waits for notification from the started thread that initialisation is complete before returning.
Definition at line 270 of file thread.cc.
References impala::Promise< T >::Get(), and impala::thread_manager.
Referenced by Thread().
|
staticprivate |
Wrapper for the user-supplied function. Always invoked from thread_. Executes the method in functor_, but before doing so registers with the global ThreadMgr and reads the thread's system TID. After the method terminates, it is unregistered. SuperviseThread() notifies StartThread() when thread initialisation is completed via the promise parameter, which is set to the new thread's system ID. After this point, it is no longer safe for SuperviseThread() to refer to parameters passed by reference or pointer to this method, because of a wrinkle in the lifecycle of boost threads: if the thread object representing a thread should be destroyed, the actual operating-system thread continues to run (the thread is detached, not terminated). Therefore it's not safe to make reference to the Thread object or any of its members in SuperviseThread() after it notifies the caller via thread_started that initialisation is completed. An alternative is to join() in the destructor of Thread, but that's not the same semantics as boost::thread, which we are trying to emulate here. As a result, the 'functor' parameter is deliberately copied into this method, since it is used after the notification completes.h The tid parameter is written to exactly once before SuperviseThread() notifies the caller.
Definition at line 288 of file thread.cc.
References impala::GetStrErrMsg(), impala::name, impala::Promise< T >::Set(), and impala::thread_manager.
|
inline |
The thread ID assigned to this thread by the operating system. If the OS does not support retrieving the tid, returns Thread::INVALID_THREAD_ID.
Definition at line 106 of file thread.h.
References tid_.
Referenced by impala::CgroupsMgr::AssignThreadToCgroup().
|
private |
|
static |
|
private |
The actual thread object that runs the user's method via SuperviseThread().
Definition at line 120 of file thread.h.
Referenced by Join().
|
private |
OS-specific thread ID. Set to UNINITIALISED_THREAD_ID initially, but once the constructor returns from StartThread() the tid_ is guaranteed to be set either to a non-negative integer, or INVALID_THREAD_ID.
Definition at line 129 of file thread.h.
Referenced by tid().
|
staticprivate |