This is the mail archive of the
ecos-discuss@sources.redhat.com
mailing list for the eCos project.
how to wait for a thread to complete?
- From: Øyvind Harboe <oyvind dot harboe at zylin dot com>
- To: ecos-discuss at sources dot redhat dot com
- Date: Fri, 23 Jul 2004 10:21:04 +0200
- Subject: [ECOS] how to wait for a thread to complete?
I've tried and failed to find a reasonable way to wait for
a thread to run to completion in eCos. By "run to completion",
I mean that the thread might yet do useful work(including e.g.
network communication, processing, etc.).
cyg_thread_delete() will break a thread out of its sleep, which
I don't want.
Setting a flag just before I return from the thread entry fn is not
satisfactory, because it could cause me to reuse the stack
prematurely and a subsequent cyg_thread_delete() *could* fail.
So, I propose that a new API fn in eCos is called for. Something along
the lines in the attached patch.
With regards to the implementation, I would have liked for the
cyg_thread_delay() to be replaced by something that caused
cyg_thread_wait_exited() to wake up *immediately* after the thread has
entered the exited state, but I couldn't find an obvious and simple way
to do so.
--
Øyvind Harboe
http://www.zylin.com
Index: ChangeLog
===================================================================
RCS file: /cvs/ecos/ecos/packages/kernel/current/ChangeLog,v
retrieving revision 1.119
diff -w -u -r1.119 ChangeLog
--- ChangeLog 16 Apr 2004 03:33:59 -0000 1.119
+++ ChangeLog 23 Jul 2004 08:10:47 -0000
@@ -1,3 +1,13 @@
+2004-07-23 Oyvind Harboe <oyvind.harboe@zylin.com>
+
+ * src/common/thread.cxx:
+ * include/kapi.h:
+ added cyg_thread_wait_exited(). It waits for the thread passed in
+ as an argument to enter the exited state, i.e. for the thread to
+ run to completion. There is no obvious way to do this with the
+ existing API. Immediately after this fn returns the stack can be
+ reused.
+
2004-04-15 Jonathan Larmour <jifl@eCosCentric.com>
* tests/fptest.c (do_test): Silence aliasing warning when breaking
Index: include/kapi.h
===================================================================
RCS file: /cvs/ecos/ecos/packages/kernel/current/include/kapi.h,v
retrieving revision 1.20
diff -w -u -r1.20 kapi.h
--- include/kapi.h 15 Mar 2004 15:20:53 -0000 1.20
+++ include/kapi.h 23 Jul 2004 08:10:47 -0000
@@ -173,6 +173,8 @@
void cyg_thread_kill(cyg_handle_t thread) __THROW;
+void cyg_thread_wait_exited(cyg_handle_t thread) __THROW;
+
void cyg_thread_release(cyg_handle_t thread) __THROW;
void cyg_thread_yield(void) __THROW;
Index: src/common/kapi.cxx
===================================================================
RCS file: /cvs/ecos/ecos/packages/kernel/current/src/common/kapi.cxx,v
retrieving revision 1.24
diff -w -u -r1.24 kapi.cxx
--- src/common/kapi.cxx 15 Mar 2004 15:20:53 -0000 1.24
+++ src/common/kapi.cxx 23 Jul 2004 08:10:48 -0000
@@ -221,6 +221,16 @@
((Cyg_Thread *)thread)->kill();
}
+externC void cyg_thread_wait_exited( cyg_handle_t thread) __THROW
+{
+ Cyg_Thread *th = (Cyg_Thread *)thread;
+ while ( th->get_state() != Cyg_Thread::EXITED )
+ {
+ cyg_thread_delay(1);
+ }
+}
+
+
externC void cyg_thread_release( cyg_handle_t thread) __THROW
{
((Cyg_Thread *)thread)->release();
--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss