22 #ifndef KALDI_THREAD_KALDI_THREAD_H_ 23 #define KALDI_THREAD_KALDI_THREAD_H_ 1 120 threads_(std::max<
int32>(1, num_threads)),
121 cvec_(std::max<
int32>(1, num_threads), c_in) {
122 if (num_threads == 0) {
126 cvec_[0].thread_id_ = 0;
127 cvec_[0].num_threads_ = 1;
130 for (
int32 i = 0;
i < threads_.size();
i++) {
131 cvec_[
i].thread_id_ =
i;
132 cvec_[
i].num_threads_ = threads_.size();
133 threads_[
i] = std::thread(std::ref(cvec_[
i]));
138 for (
size_t i = 0;
i < threads_.size();
i++)
139 if (threads_[
i].joinable())
161 opts->
Register(
"num-threads", &num_threads,
"Number of actively processing " 162 "threads to run in parallel");
163 opts->
Register(
"num-threads-total", &num_threads_total,
"Total number of " 164 "threads, including those that are waiting on other threads " 165 "to produce their output. Controls memory use. If <= 0, " 166 "defaults to --num-threads plus 20. Otherwise, must " 167 "be >= num-threads.");
179 threads_avail_(config.num_threads),
180 tot_threads_avail_(config.num_threads_total > 0 ? config.num_threads_total :
181 config.num_threads + 20),
185 "num-threads-total, if specified, must be >= num-threads");
198 threads_avail_.Wait();
199 tot_threads_avail_.Wait();
211 if (thread_list_ != NULL) {
212 thread_list_->thread.join();
231 me(me), c(c), tail(tail) {}
246 if (args->
tail != NULL) {
257 if (args->
tail != NULL) {
285 #endif // KALDI_THREAD_KALDI_THREAD_H_ virtual void operator()()=0
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
TaskSequencer(const TaskSequencerConfig &config)
void Run(C *c)
This function takes ownership of the pointer "c", and will delete it in the same sequence as Run was ...
static void RunTask(RunTaskArgsList *args)
void Signal()
increase the counter
MultiThreader(int32 num_threads, const C &c_in)
Semaphore tot_threads_avail_
virtual void Register(const std::string &name, bool *ptr, const std::string &doc)=0
virtual ~MultiThreadable()
RunTaskArgsList * thread_list_
void RunMultiThreaded(const C &c_in)
Here, class C should inherit from MultiThreadable.
RunTaskArgsList(TaskSequencer *me, C *c, RunTaskArgsList *tail)
#define KALDI_ASSERT(cond)
~TaskSequencer()
The destructor waits for the last thread to exit.
void Register(OptionsItf *opts)
std::vector< std::thread > threads_