Skip to content

Commit 253b0b5

Browse files
committed
..
1 parent f81cbd2 commit 253b0b5

2 files changed

Lines changed: 63 additions & 0 deletions

File tree

cpp.boost/thread.pool/main.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
}

cpp.c++20/jthread/CMakeLists.txt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+

0 commit comments

Comments
 (0)