From ef18f4d579b90344eff045dcc29d15048310e6bc Mon Sep 17 00:00:00 2001 From: Georgi Gerganov Date: Sun, 22 Oct 2023 16:55:40 +0300 Subject: [PATCH] server : fix crash in Debug on macOS (I have no idea why this fixes it!?) --- examples/server/server.cpp | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/examples/server/server.cpp b/examples/server/server.cpp index cdc643ffe..105b6d92e 100644 --- a/examples/server/server.cpp +++ b/examples/server/server.cpp @@ -2440,20 +2440,31 @@ int main(int argc, char **argv) {"hostname", sparams.hostname}, {"port", sparams.port}, }); - std::thread t([&llama]() - { - bool running = true; - while (running) - { - running = llama.update_slots(); - } - } - ); - if (!svr.listen_after_bind()) + // run the HTTP server in a thread - see comment below + std::thread t([&]() + { + if (!svr.listen_after_bind()) + { + return 1; + } + + return 0; + }); + + // GG: if I put the main loop inside a thread, it crashes on the first request when build in Debug!? + // "Bus error: 10" - this is on macOS, it does not crash on Linux + //std::thread t2([&]() { - return 1; + bool running = true; + while (running) + { + running = llama.update_slots(); + } } + //); + + t.join(); llama_backend_free(); return 0;