Skip to content

Commit 92dbf19

Browse files
committed
Update uS, fix threaded prints
1 parent 0a44518 commit 92dbf19

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

examples/HelloWorldThreaded.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#include "App.h"
22
#include <thread>
33
#include <algorithm>
4+
#include <mutex>
5+
6+
std::mutex m;
47

58
int main() {
69
/* Overly simple hello world app, using multiple threads */
@@ -12,11 +15,13 @@ int main() {
1215
uWS::App().get("/*", [](auto *res, auto * /*req*/) {
1316
res->end("Hello world!");
1417
}).listen(3000, [](auto *listen_socket) {
18+
m.lock();
1519
if (listen_socket) {
1620
std::cout << "Thread " << std::this_thread::get_id() << " listening on port " << 3000 << std::endl;
1721
} else {
1822
std::cout << "Thread " << std::this_thread::get_id() << " failed to listen on port 3000" << std::endl;
1923
}
24+
m.unlock();
2025
}).run();
2126

2227
});

uSockets

Submodule uSockets updated 1 file

0 commit comments

Comments
 (0)