5 changed files with 82 additions and 4 deletions
@ -1,8 +1,12 @@ |
|||||
cmake_minimum_required(VERSION 3.0) |
cmake_minimum_required(VERSION 3.0) |
||||
|
|
||||
set(CMAKE_C_STANDARD 99) |
set(CMAKE_CXX_STANDARD 11) |
||||
|
|
||||
project(tiny_thread_pool LANGUAGES C) |
project(tiny_thread_demo LANGUAGES CXX) |
||||
|
|
||||
add_executable(tiny_pool main.c tiny_pool.c) |
include_directories(src) |
||||
target_link_libraries(tiny_pool pthread) |
|
||||
|
add_subdirectory(src) |
||||
|
|
||||
|
add_executable(demo demo.cc) |
||||
|
target_link_libraries(demo tiny_pool) |
||||
|
@ -0,0 +1,34 @@ |
|||||
|
#include <iostream> |
||||
|
#include <unistd.h> |
||||
|
#include "tiny_pool.h" |
||||
|
|
||||
|
void demo_func(void *arg) { |
||||
|
|
||||
|
std::cout << *(int*)arg << std::endl; |
||||
|
|
||||
|
sleep(1); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
int main() { |
||||
|
std::cout << "tiny thread pool demo start" << std::endl; |
||||
|
|
||||
|
|
||||
|
auto pool = tiny_pool_create(3); |
||||
|
|
||||
|
int dat[] = {0, 1, 2, 3, 4, 5, 6}; |
||||
|
tiny_pool_submit(pool, demo_func, (void*)&dat[0]); |
||||
|
tiny_pool_submit(pool, demo_func, (void*)&dat[1]); |
||||
|
tiny_pool_submit(pool, demo_func, (void*)&dat[2]); |
||||
|
tiny_pool_submit(pool, demo_func, (void*)&dat[3]); |
||||
|
tiny_pool_submit(pool, demo_func, (void*)&dat[4]); |
||||
|
tiny_pool_submit(pool, demo_func, (void*)&dat[5]); |
||||
|
tiny_pool_submit(pool, demo_func, (void*)&dat[6]); |
||||
|
|
||||
|
tiny_pool_boot(pool); |
||||
|
|
||||
|
tiny_pool_join(pool); |
||||
|
|
||||
|
std::cout << "tiny thread pool demo exit" << std::endl; |
||||
|
return 0; |
||||
|
} |
@ -0,0 +1,8 @@ |
|||||
|
cmake_minimum_required(VERSION 3.0) |
||||
|
|
||||
|
set(CMAKE_C_STANDARD 99) |
||||
|
|
||||
|
project(tiny_thread_pool LANGUAGES C) |
||||
|
|
||||
|
add_library(tiny_pool tiny_pool.c) |
||||
|
target_link_libraries(tiny_pool pthread) |
Loading…
Reference in new issue