[DIST] Enable multiple thread and tracker, make rabit and xgboost more thread-safe by using thread local variables.
This commit is contained in:
@@ -4,12 +4,20 @@
|
||||
* \brief Enable all kinds of global variables in common.
|
||||
*/
|
||||
#include "./random.h"
|
||||
#include "./thread_local.h"
|
||||
|
||||
namespace xgboost {
|
||||
namespace common {
|
||||
/*! \brief thread local entry for random. */
|
||||
struct RandomThreadLocalEntry {
|
||||
/*! \brief the random engine instance. */
|
||||
GlobalRandomEngine engine;
|
||||
};
|
||||
|
||||
typedef ThreadLocalStore<RandomThreadLocalEntry> RandomThreadLocalStore;
|
||||
|
||||
GlobalRandomEngine& GlobalRandom() {
|
||||
static GlobalRandomEngine inst;
|
||||
return inst;
|
||||
return RandomThreadLocalStore::Get()->engine;
|
||||
}
|
||||
}
|
||||
} // namespace xgboost
|
||||
|
||||
@@ -61,7 +61,8 @@ typedef RandomEngine GlobalRandomEngine;
|
||||
|
||||
/*!
|
||||
* \brief global singleton of a random engine.
|
||||
* Only use this engine when necessary, not thread-safe.
|
||||
* This random engine is thread-local and
|
||||
* only visible to current thread.
|
||||
*/
|
||||
GlobalRandomEngine& GlobalRandom(); // NOLINT(*)
|
||||
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
#ifndef XGBOOST_COMMON_THREAD_LOCAL_H_
|
||||
#define XGBOOST_COMMON_THREAD_LOCAL_H_
|
||||
|
||||
#include <dmlc/base.h>
|
||||
|
||||
#if DMLC_ENABLE_STD_THREAD
|
||||
#include <mutex>
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user