From 6560d4b86571787386893fb0301d71b4b7bc458f Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Fri, 4 Aug 2023 11:01:24 -0400 Subject: [PATCH] fix: wait for threads to terminate when shutting down server --- src/Tiny_httpd_server.ml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Tiny_httpd_server.ml b/src/Tiny_httpd_server.ml index f1879bde..26624d4b 100644 --- a/src/Tiny_httpd_server.ml +++ b/src/Tiny_httpd_server.ml @@ -971,6 +971,9 @@ module Unix_tcp_server_ = struct k "Unix.accept or Thread.create raised an exception: %s" (Printexc.to_string e)) done; + + (* Wait for all threads to be done: this only works if all threads are done. *) + Sem_.acquire self.sem_max_connections.max self.sem_max_connections; ()); } end