File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #include < iostream>
2+ #include < mutex>
3+
4+ #include " sys/asio_threadpool.hpp"
5+
6+ using namespace std ;
7+
8+ mutex io_mutex;
9+
10+ void hello (int value)
11+ {
12+ unique_lock l (io_mutex);
13+ cout << " thead id: " << this_thread::get_id () << " " ;
14+ cout << " hello value : " << value << " \n " ;
15+ cout.flush ();
16+ }
17+
18+ int main (int argc, char const * argv[])
19+ {
20+ sys::threadpool pool (5 );
21+ pool.start ();
22+
23+ int const data_count = 1000 ;
24+ for (int i=0 ; i<data_count; i++)
25+ pool.post ([i]() { hello (i); });
26+
27+ cout << " made " << data_count << " \n " ;
28+ sleep (3 );
29+ // thread th([&pool]() { sleep(3); pool.stop(); });
30+ // pool.join();
31+ // th.join();
32+
33+ return 0 ;
34+ }
Original file line number Diff line number Diff line change 1+ cmake_minimum_required (VERSION 3.26 )
2+
3+ project (jthread)
4+
5+ set (CMAKE_CXX_STANDARD 23)
6+ set (CMAKE_EXPORT_COMPILE_COMMANDS ON )
7+
8+ set (SOURCES
9+ jthread.cpp
10+ )
11+
12+ include_directories (
13+ /usr/local/include
14+ /opt/homebrew/include
15+ ${CMAKE_CURRENT_SOURCE_DIR}
16+ )
17+
18+ link_directories (
19+ /usr/local/lib
20+ /opt/homebrew/lib
21+ )
22+
23+ add_executable (jthread ${SOURCES} )
24+
25+ target_link_libraries (jthread
26+ # lib name 1
27+ # lib name 2
28+ )
29+
You can’t perform that action at this time.
0 commit comments