File tree Expand file tree Collapse file tree 3 files changed +21
-7
lines changed
Expand file tree Collapse file tree 3 files changed +21
-7
lines changed Original file line number Diff line number Diff line change 3030* .exe
3131* .out
3232* .app
33+
34+
35+ build- * /
36+ /test /CMakeLists.txt.user
Original file line number Diff line number Diff line change 1+ cmake_minimum_required (VERSION 3.7)
2+
3+ project (test -ctrl-c)
4+
5+ add_executable (${PROJECT_NAME} "main.cpp" "../src/ctrl-c.h" "../src/ctrl-c.cpp" )
6+ target_include_directories (${PROJECT_NAME} PRIVATE "../src" )
Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ SOFTWARE.
2626#include < condition_variable>
2727#include < mutex>
2828
29- #include " ../src/ ctrl-c.h"
29+ #include " ctrl-c.h"
3030
3131int main ()
3232{
@@ -38,22 +38,26 @@ int main()
3838 unsigned int handler_id = CtrlCLibrary::SetCtrlCHandler ([&catches, &wait_lock, &wait_var](enum CtrlCLibrary::CtrlSignal event) -> bool {
3939 switch (event) {
4040 case CtrlCLibrary::kCtrlCSignal :
41- std::cout << " Catch Ctrl+C" << std::endl;
41+ std::cout << " Caught Ctrl+C" << std::endl;
42+ std::lock_guard<std::mutex> locker (wait_lock);
43+ ++catches;
44+ wait_var.notify_all ();
4245 }
43- std::lock_guard<std::mutex> locker (wait_lock);
44- ++catches;
45- wait_var.notify_all ();
4646 return true ;
4747 });
4848 if (handler_id == CtrlCLibrary::kErrorID ) {
4949 std::cerr << " Can't set ctrl+c handler" << std::endl;
50- return 0 ;
50+ return 1 ;
5151 }
52+
5253 std::cout << " Press Ctrl+C " << kMaxCatches << " times" << std::endl;
5354 std::unique_lock<std::mutex> locker (wait_lock);
54- wait_var.wait (locker, [&catches, kMaxCatches ](){
55+ wait_var.wait (locker, [&catches](){
5556 return catches >= kMaxCatches ;
5657 });
58+ std::cout << " All Ctrl+C's pressed" << std::endl;
59+
5760 CtrlCLibrary::ResetCtrlCHandler (handler_id);
61+
5862 return 0 ;
5963}
You can’t perform that action at this time.
0 commit comments