Update uS, fix threaded prints
This commit is contained in:
@@ -1,6 +1,9 @@
|
|||||||
#include "App.h"
|
#include "App.h"
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
|
std::mutex m;
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
/* Overly simple hello world app, using multiple threads */
|
/* Overly simple hello world app, using multiple threads */
|
||||||
@@ -12,11 +15,13 @@ int main() {
|
|||||||
uWS::App().get("/*", [](auto *res, auto * /*req*/) {
|
uWS::App().get("/*", [](auto *res, auto * /*req*/) {
|
||||||
res->end("Hello world!");
|
res->end("Hello world!");
|
||||||
}).listen(3000, [](auto *listen_socket) {
|
}).listen(3000, [](auto *listen_socket) {
|
||||||
|
m.lock();
|
||||||
if (listen_socket) {
|
if (listen_socket) {
|
||||||
std::cout << "Thread " << std::this_thread::get_id() << " listening on port " << 3000 << std::endl;
|
std::cout << "Thread " << std::this_thread::get_id() << " listening on port " << 3000 << std::endl;
|
||||||
} else {
|
} else {
|
||||||
std::cout << "Thread " << std::this_thread::get_id() << " failed to listen on port 3000" << std::endl;
|
std::cout << "Thread " << std::this_thread::get_id() << " failed to listen on port 3000" << std::endl;
|
||||||
}
|
}
|
||||||
|
m.unlock();
|
||||||
}).run();
|
}).run();
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
+1
-1
Submodule uSockets updated: 2b96d4b517...c1af42e657
Reference in New Issue
Block a user