Skip to content

Commit 4ee8aee

Browse files
committed
Example to disable std::this_thread::sleep_for.
1 parent 4139949 commit 4ee8aee

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

example/ssecli.cc

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,25 @@
1111
using namespace std;
1212

1313
int main(void) {
14-
httplib::Client("http://localhost:1234")
15-
.Get("/event1", [&](const char *data, size_t data_length) {
16-
std::cout << string(data, data_length);
17-
return true;
18-
});
14+
std::vector<std::thread> threads;
15+
16+
size_t threead_count = 64;
17+
18+
for (size_t i = 0; i < threead_count; i++) {
19+
threads.push_back(std::thread{[&, i] {
20+
httplib::Client("http://localhost:1234")
21+
.Get("/event1", [&, i](const char *data, size_t data_length) {
22+
if (i == threead_count - 1) {
23+
std::cout << string(data, data_length);
24+
}
25+
return true;
26+
});
27+
}});
28+
}
29+
30+
for (auto &t : threads) {
31+
t.join();
32+
}
1933

2034
return 0;
2135
}

example/ssesvr.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ using namespace std;
1212

1313
class EventDispatcher {
1414
public:
15-
EventDispatcher() {
16-
}
15+
EventDispatcher() {}
1716

1817
void wait_event(DataSink *sink) {
1918
unique_lock<mutex> lk(m_);
@@ -64,6 +63,10 @@ int main(void) {
6463

6564
Server svr;
6665

66+
svr.new_task_queue = [] {
67+
return new ThreadPool(/*num_threads=*/128, /*max_queued_requests=*/256);
68+
};
69+
6770
svr.Get("/", [&](const Request & /*req*/, Response &res) {
6871
res.set_content(html, "text/html");
6972
});

0 commit comments

Comments
 (0)