1
0

threadpool_test.cpp 429 B

1234567891011121314151617181920212223242526272829
  1. #include <stdio.h>
  2. #include "hthreadpool.h"
  3. #include "htime.h"
  4. void print_task(int i) {
  5. printf("thread[%x]: task[%d]\n", gettid(), i);
  6. sleep(1);
  7. }
  8. int main(int argc, char** argv) {
  9. HThreadPool tp(4);
  10. tp.start();
  11. int i = 0;
  12. for (; i < 10; ++i) {
  13. tp.commit(print_task, i);
  14. }
  15. tp.wait();
  16. for (; i < 20; ++i) {
  17. tp.commit(print_task, i);
  18. }
  19. tp.wait();
  20. return 0;
  21. }