Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/lib/libpthread It is perfectly valid for sem_wait to b...



details:   https://anonhg.NetBSD.org/src/rev/efc2e8491a79
branches:  trunk
changeset: 777925:efc2e8491a79
user:      joerg <joerg%NetBSD.org@localhost>
date:      Fri Mar 09 19:46:37 2012 +0000

description:
It is perfectly valid for sem_wait to be interrupted, so loop on EINTR.

diffstat:

 tests/lib/libpthread/t_sem.c |  13 ++++++++-----
 1 files changed, 8 insertions(+), 5 deletions(-)

diffs (39 lines):

diff -r 095bdf009355 -r efc2e8491a79 tests/lib/libpthread/t_sem.c
--- a/tests/lib/libpthread/t_sem.c      Fri Mar 09 18:54:28 2012 +0000
+++ b/tests/lib/libpthread/t_sem.c      Fri Mar 09 19:46:37 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: t_sem.c,v 1.6 2012/03/07 23:31:44 joerg Exp $ */
+/* $NetBSD: t_sem.c,v 1.7 2012/03/09 19:46:37 joerg Exp $ */
 
 /*
  * Copyright (c) 2008, 2010 The NetBSD Foundation, Inc.
@@ -86,7 +86,7 @@
 #include <sys/cdefs.h>
 __COPYRIGHT("@(#) Copyright (c) 2008, 2010\
  The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_sem.c,v 1.6 2012/03/07 23:31:44 joerg Exp $");
+__RCSID("$NetBSD: t_sem.c,v 1.7 2012/03/09 19:46:37 joerg Exp $");
 
 #include <errno.h>
 #include <fcntl.h>
@@ -230,14 +230,17 @@
 static void *
 threadfunc(void *arg)
 {
-       int i;
+       int i, ret;
 
        printf("Entering loop\n");
        for (i = 0; i < 500; ) {
                if ((i & 1) != 0) {
-                       ATF_REQUIRE(sem_wait(&sem) != -1);
+                       do {
+                               ret = sem_wait(&sem);
+                       } while (ret == -1 && errno == EINTR);
+                       ATF_REQUIRE(ret == 0);
                } else {
-                       const int ret = sem_trywait(&sem);
+                       ret = sem_trywait(&sem);
                        if (ret == -1) {
                                ATF_REQUIRE(errno == EAGAIN);
                                continue;



Home | Main Index | Thread Index | Old Index