[sheepdog] [PATCH] work: make short thread DETACHED
Liu Yuan
namei.unix at gmail.com
Tue Jul 3 11:33:38 CEST 2012
From: Liu Yuan <tailai.ly at taobao.com>
This is need to release pthread resource.
Signed-off-by: Liu Yuan <tailai.ly at taobao.com>
---
sheep/work.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/sheep/work.c b/sheep/work.c
index 618c9dd..a88d2aa 100644
--- a/sheep/work.c
+++ b/sheep/work.c
@@ -63,6 +63,9 @@ static void *run_short_thread(void *arg)
eventfd_t value = 1;
static uint64_t idx = 0;
+ /* Tell runtime to release resources after termination */
+ pthread_detach(pthread_self());
+
set_thread_name(sw->wi->name, uatomic_add_return(&idx, 1));
sw->work->fn(sw->work);
@@ -73,7 +76,7 @@ static void *run_short_thread(void *arg)
eventfd_write(efd, value);
free(sw);
- return NULL;
+ pthread_exit(NULL);
}
static inline void create_short_thread(struct worker_info *wi,
@@ -81,11 +84,14 @@ static inline void create_short_thread(struct worker_info *wi,
{
pthread_t thread;
struct short_work *sw = xmalloc(sizeof *sw);
+ int err;
sw->work = work;
sw->wi = wi;
- if (pthread_create(&thread, NULL, run_short_thread, sw))
- panic("%m\n");
+
+ err = pthread_create(&thread, NULL, run_short_thread, sw);
+ if (err)
+ panic("%s\n", strerror(err));
}
void queue_work(struct work_queue *q, struct work *work)
--
1.7.10.2
More information about the sheepdog
mailing list