Skip to content

A simple sample of apply this threadpool #113

Description

@lix19937
#include <iostream>
#include "ThreadPool.h"

class MyT {
 public:
  int run(int i) { return i; }
  int init() { return 0; }
};

class MyClass {
  void loopDoSomething() {}
  void sayHello() { std::thread t(&MyClass::loopDoSomething, this); }
};

int main() {
  ThreadPool pool(4);
  MyT myt;

  for (int i = 0; i < 6; ++i) {
    // enqueue and store future
    auto result = pool.enqueue([](int answer) { return answer; }, 42);

    auto result2 = pool.enqueue(&MyT::run, &myt, i);

    // get result from future
    std::cout << result.get() << std::endl;
    std::cout << result2.get() << std::endl;

    std::cout << "\n" << std::endl;
  }

  return 0;
}

  // if (0) {
  //   WorkFlow wf;
  //   __LOG_DEBUG("%p ", &wf);
  //   wf.Init(cfgs[0]);
  //   __LOG_DEBUG("%p ", &wf);
  //   std::thread t1(&WorkFlow::Run, &wf, &runtime_tensor, 1);
  //   t1.join();
  // }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions