[DIST] Enable multiple thread and tracker, make rabit and xgboost more thread-safe by using thread local variables.

This commit is contained in:
tqchen
2016-03-03 11:36:34 -08:00
parent 12dc92f7e0
commit e80d3db64b
17 changed files with 323 additions and 153 deletions

View File

@@ -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

View File

@@ -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(*)

View File

@@ -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