From ecbe89613c7c0421f8f09267ad057dcbc71b087c Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Tue, 3 Jun 2014 17:04:10 +0200 Subject: Create threads in detached state --- src/fastd.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'src/fastd.c') diff --git a/src/fastd.c b/src/fastd.c index 1841c42..b5cc758 100644 --- a/src/fastd.c +++ b/src/fastd.c @@ -40,7 +40,6 @@ #include #include -#include #include #include #include @@ -539,6 +538,15 @@ static inline void init(int argc, char *argv[]) { ctx.next_maintenance = fastd_in_seconds(MAINTENANCE_INTERVAL); ctx.unknown_handshakes[0].timeout = ctx.now; + VECTOR_ALLOC(ctx.eth_addrs, 0); + VECTOR_ALLOC(ctx.peers, 0); + VECTOR_ALLOC(ctx.async_pids, 0); + + if (pthread_attr_init(&ctx.detached_thread)) + exit_errno("pthread_attr_init"); + if (pthread_attr_setdetachstate(&ctx.detached_thread, PTHREAD_CREATE_DETACHED)) + exit_errno("pthread_attr_setdetachstate"); + pr_info("fastd " FASTD_VERSION " starting"); fastd_cap_init(); @@ -558,10 +566,6 @@ static inline void init(int argc, char *argv[]) { set_groups(); write_pid(); - VECTOR_ALLOC(ctx.eth_addrs, 0); - VECTOR_ALLOC(ctx.peers, 0); - VECTOR_ALLOC(ctx.async_pids, 0); - fastd_peer_hashtable_init(); #ifdef ENABLE_SYSTEMD @@ -681,6 +685,8 @@ static inline void cleanup(void) { fastd_peer_hashtable_free(); + pthread_attr_destroy(&ctx.detached_thread); + VECTOR_FREE(ctx.async_pids); VECTOR_FREE(ctx.peers); VECTOR_FREE(ctx.eth_addrs); -- cgit v1.2.3