initial commit
This commit is contained in:
30
third_party/libhv/unittest/threadpool_test.cpp
vendored
Executable file
30
third_party/libhv/unittest/threadpool_test.cpp
vendored
Executable file
@@ -0,0 +1,30 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "hthreadpool.h"
|
||||
#include "hthread.h"
|
||||
#include "htime.h"
|
||||
|
||||
void print_task(int i) {
|
||||
printf("thread[%ld]: task[%d]\n", hv_gettid(), i);
|
||||
hv_sleep(1);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
HThreadPool tp(1, 4);
|
||||
tp.start();
|
||||
|
||||
int i = 0;
|
||||
for (; i < 10; ++i) {
|
||||
tp.commit(print_task, i);
|
||||
}
|
||||
|
||||
tp.wait();
|
||||
|
||||
for (; i < 20; ++i) {
|
||||
tp.commit(print_task, i);
|
||||
}
|
||||
|
||||
tp.wait();
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user