线程池ThreadPool

本文详细介绍了TensorFlow中线程池类的定义及使用方法。主要涉及线程池构造函数的不同形式及其参数意义,如环境配置、线程选项、线程数量等。此外还阐述了线程池的主要成员函数,包括任务调度、并行循环等功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


tensorflow::tensorflow/core/lib/core/threadpool.h

namespace tensorflow {
namespace thread {
class ThreadPool {
 public:
  ThreadPool(Env* env, const ThreadOptions& thread_options, const string& name,
             int num_threads, bool low_latency_hint);
  ThreadPool(Env* env, const string& name, int num_threads);
  ThreadPool(Env* env, const ThreadOptions& thread_options, const string& name,
             int num_threads);
  ~ThreadPool();
  void Schedule(std::function<void()> fn);
 
  void ParallelFor(int64 total, int64 cost_per_unit,
                   std::function<void(int64, int64)> fn);
  void ParallelForWithWorkerId(
      int64 total, int64 cost_per_unit,
      const std::function<void(int64, int64, int)>& fn);
  int NumThreads() const;
  int CurrentThreadId() const;
  struct Impl;
 private:
  std::unique_ptr<Impl> impl_;
  TF_DISALLOW_COPY_AND_ASSIGN(ThreadPool);
};
}
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值