diff --git a/skynet-src/skynet_start.c b/skynet-src/skynet_start.c index 371290bf..f590fd3b 100644 --- a/skynet-src/skynet_start.c +++ b/skynet-src/skynet_start.c @@ -55,30 +55,43 @@ _socket(void *p) { int r = skynet_socket_poll(); if (r==0) break; - if (r<0) + if (r<0) { + CHECK_ABORT continue; + } wakeup(m,0); } return NULL; } +static void +free_monitor(struct monitor *m) { + int i; + int n = m->count; + for (i=0;im[i]); + } + pthread_mutex_destroy(&m->mutex); + pthread_cond_destroy(&m->cond); + free(m->m); + free(m); +} + static void * _monitor(void *p) { struct monitor * m = p; int i; int n = m->count; for (;;) { + CHECK_ABORT for (i=0;im[i]); } - CHECK_ABORT - sleep(5); + for (i=0;i<5;i++) { + CHECK_ABORT + sleep(1); + } } - for (i=0;im[i]); - } - free(m->m); - free(m); return NULL; } @@ -92,6 +105,10 @@ _timer(void *p) { wakeup(m,m->count-1); usleep(2500); } + // wakeup socket thread + skynet_socket_exit(); + // wakeup all worker thread + pthread_cond_broadcast(&m->cond); return NULL; } @@ -154,11 +171,11 @@ _start(int thread) { create_thread(&pid[i+3], _worker, &wp[i]); } - for (i=1;imutex); - pthread_cond_destroy(&m->cond); + + free_monitor(m); } static int