본문 바로가기

C.C++14

thread_group #pragma once #include #include #include class thread_group{private: //포인터 컨테이너std::vector container; public:thread_group(){}virtual ~thread_group(){//소멸자 호출시 join 후join_all(); //쓰레드 deletefor(auto& thread : container) delete thread;}; //다른 쓰레드그룹 대입 및 복사 금지thread_group(const thread_group&) = delete;thread_group& operator=(const thread_group&) = delete; //기본 new로 하거나 bind를 통해서 생성된 경우를 위해 template로.. 2018. 4. 24.
asio 타이머 핸들링 예제 #include #include #include #include #include #include #include std::mutex global_stream_lock; void WorkerThread(std::shared_ptr iosvc, int counter){global_stream_lock.lock();std::cout 2018. 4. 17.
asio io_service 한방이해 #include #include #include #include #include asio::io_service io_svc;int a = 0; void WorkerThread(){std::cout 2018. 4. 15.
예외처리가 안되었을 경우에 terminate 에서 abort 말고 커스텀 함수 호출하는 법 c++에서는 Exception이 throw 됐을 때 처리되지 않으면(catch 구문을 통해 맞는 catch 구문을 찾을 수 없을 경우) terminate를 호출하고, 이 terminate는 기본으로 abort를 호출한다. (terminate : http://www.cplusplus.com/reference/exception/terminate/) 보통 이런 경우는 개발자가 실수한 경우이기 때문에 이런 경우에서 조금이라도 도움을 주기 위해서 abort 외에 다른 함수를 호출하여 처리되지 않았음을 알려줄 수 있지 않을까? 해서 쓴다. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 #include void plus(int * ptr) { if(!ptr) throw std::in.. 2017. 12. 10.