fixes for multi thread support
[NeonServV5.git] / src / main.c
index 60b7ec6ac4b37fb9e1f5f08f95ea29a0c02b176b..4ad2d0d5c0f13626048ecb4833c6f51266be678e 100644 (file)
@@ -42,6 +42,9 @@ static int running, hard_restart;
 static int statistics_requested_lusers = 0;
 int statistics_enabled;
 TIMEQ_CALLBACK(main_statistics);
+#ifdef HAVE_THREADS
+int running_threads;
+#endif
 
 void cleanup() {
     free_sockets();
@@ -106,6 +109,7 @@ void * thread_main(void *arg) {
         destroyEvents();
         queue_loop();
     }
+    running_threads--;
     return NULL;
 }
 #endif
@@ -132,6 +136,7 @@ main:
     statistics_enabled = get_int_field("statistics.enable");
     
     queue_init();
+    init_sockets();
     init_timeq();
     init_lang();
     ssl_init();
@@ -160,11 +165,13 @@ main:
     pthread_t tid[worker_threads];
     int tid_id = 0;
     for(tid_id = 0; tid_id < worker_threads; tid_id++) {
+        running_threads++;
         pthread_create(&tid[tid_id], NULL, thread_main, NULL);
     }
     for(tid_id = 0; tid_id < worker_threads; tid_id++) {
         pthread_join(tid[tid_id], NULL);
     }
+    running_threads = 0;
     #else
     time_t socket_wait;
     while(running) {