IOCP를 활용한 쓰레드 풀
처음 작성한 코드
code : https://github.com/EomTaeWook/Cpp-IOCPThreadPool
//계속 개선될 소스임.
code : https://github.com/EomTaeWook/Cpp-Util/tree/master/Util/Threading
main.cpp
#include "../ThreadPoolLib/IOCPThreadPool.h"
bool stop1 = true;
bool stop2 = true;
bool stop3 = true;
bool stop4 = true;
bool arr[10000] = { false };
void Sum(void *p)
{
auto value = static_cast<int*>(p);
printf("Stop 1 %d\n", *value);
stop1 = false;
}
void Sum1(void *p)
{
auto value = static_cast<int*>(p);
printf("Stop 2 %d\n", *value);
stop2 = false;
}
void Sum2(void *p)
{
auto value = static_cast<int*>(p);
printf("Stop 3 %d\n", *value);
stop3 = false;
Sleep(1);
}
void Sum24(void *p)
{
auto value = static_cast<double*>(p);
printf("Stop 4 %lf\n", *value);
stop4 = false;
}
void Check(void *p)
{
auto value = static_cast<int*>(p);
int num = *value;
printf("Check %d\n", num);
arr[num] = true;
delete p;
Sleep(1);
}
struct Test
{
int test;
};
int main()
{
Threading::IOCPThreadPool threadpool;
threadpool.Init(3);
//singleton
Threading::IOCPThreadPool::Instance()->Init();
int a = 100;
Test t;
t.test = 200;
Test t1;
t1.test = 300;
threadpool.InsertQueueItem(std::bind(Sum, std::placeholders::_1), &a);
threadpool.InsertQueueItem(std::bind(Sum1, std::placeholders::_1), &t);
threadpool.InsertQueueItem(std::bind(Sum2, std::placeholders::_1), &t1);
double test = 10000;
threadpool.InsertQueueItem(std::bind(Sum24, std::placeholders::_1), &test);
for (int i = 0; i < 10000; i++)
{
auto val = new int(i);
threadpool.InsertQueueItem(std::bind(Sum2, std::placeholders::_1), val);
threadpool.InsertQueueItem(std::bind(Check, std::placeholders::_1), val);
}
getchar();
return 0;
}
'개발관련 > C&C++' 카테고리의 다른 글
Convert Json To Xml (0) | 2018.01.17 |
---|---|
Xmllite SAX(Simple Api for Xml) TreeNode 구현 및 LIB (XMLParser) (0) | 2018.01.11 |
임계영역(Critical Section) (0) | 2018.01.05 |
DataTable (0) | 2017.12.15 |
아두이노>초음파 센서를 이용한 물 높이 측정 (0) | 2017.07.27 |