1
0

threadpool_test.cpp 454 B

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