Skip to content

Latest commit

 

History

History
38 lines (31 loc) · 755 Bytes

README.md

File metadata and controls

38 lines (31 loc) · 755 Bytes

workthreadpool

Lightweight non-locking thread pool for multi-threading work jobs..

Usage

#include <sstream>
#include <math.h>
#include "workthreadpool.h"

class MyThreadPool : public bfd::WorkThreadPool {
 public:
  MyThreadPool(int size) : bfd::WorkThreadPool(size) {
  }
  void Handle(const string &msg) {
    stringstream ss;
    ss << "worker (" << std::this_thread::get_id() << ") got msg: " << msg;
    printf("%s\n", ss.str().c_str());
    for (int i=0; i<=999999; i++) {
      double result = sqrt(sqrt(i) / 93.234);
    }
  }
};

int main() {
  printf("start running ....\n");
  MyThreadPool pool(5);
  pool.Start();
  for (int i=0; i<100; i++) {
    pool.SendMessage("msg info ----------");
  }
  pool.Stop();

  return 0;
}