Module: xenomai-forge Branch: next Commit: d83ce07a55147c6b1c56483ba6ea2e029699b816 URL: http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=d83ce07a55147c6b1c56483ba6ea2e029699b816
Author: Philippe Gerum <r...@xenomai.org> Date: Mon Aug 25 11:54:34 2014 +0200 lib/cobalt/thread: timeout on handshake with spawned child We should have received the internal handshake from the spawned child we wait for in pthread_create_ex() within 5s, or something definitely went wrong. If we did not, time out and bail out with -EAGAIN so that we don't remain stuck indefinitely on an internal problem. --- lib/cobalt/thread.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/cobalt/thread.c b/lib/cobalt/thread.c index 8df2ce5..ef28614 100644 --- a/lib/cobalt/thread.c +++ b/lib/cobalt/thread.c @@ -179,6 +179,7 @@ int pthread_create_ex(pthread_t *ptid_r, int inherit, detachstate, ret; struct pthread_iargs iargs; struct sched_param param; + struct timespec timeout; pthread_attr_t attr; pthread_t lptid; size_t stksz; @@ -230,10 +231,14 @@ int pthread_create_ex(pthread_t *ptid_r, ret = __STD(pthread_create(&lptid, &attr, cobalt_thread_trampoline, &iargs)); if (ret) - goto fail; + goto out; + + __STD(clock_gettime(CLOCK_REALTIME, &timeout)); + timeout.tv_sec += 5; + timeout.tv_nsec = 0; for (;;) { - ret = __STD(sem_wait(&iargs.sync)); + ret = __STD(sem_timedwait(&iargs.sync, &timeout)); if (ret && errno == EINTR) continue; if (ret == 0) { @@ -241,13 +246,16 @@ int pthread_create_ex(pthread_t *ptid_r, if (ret == 0) *ptid_r = lptid; break; + } else if (errno == ETIMEDOUT) { + ret = -EAGAIN; + break; } ret = -errno; panic("regular sem_wait() failed with %s", symerror(ret)); } cobalt_thread_harden(); /* May fail if regular thread. */ -fail: +out: __STD(sem_destroy(&iargs.sync)); return ret; _______________________________________________ Xenomai-git mailing list Xenomai-git@xenomai.org http://www.xenomai.org/mailman/listinfo/xenomai-git