Module: xenomai-forge
Branch: next
Commit: 678250457f41f07c2369ada5c9a53269dfaf68a4
URL:    
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=678250457f41f07c2369ada5c9a53269dfaf68a4

Author: Philippe Gerum <r...@xenomai.org>
Date:   Mon Aug 25 11:54:34 2014 +0200

lib/cobalt/thread: timeout on handshake with spawned child

After 5s, we should have received the internal handshake from the
spawned child we wait for in pthread_create_ex(). 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 |   13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/lib/cobalt/thread.c b/lib/cobalt/thread.c
index 8df2ce5..446aa36 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,13 @@ int pthread_create_ex(pthread_t *ptid_r,
 
        ret = __STD(pthread_create(&lptid, &attr, cobalt_thread_trampoline, 
&iargs));
        if (ret)
-               goto fail;
+               goto out;
+
+       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 +245,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

Reply via email to