Fix timing issue in which one thread could be left hanging in
authoranton <anton@openbsd.org>
Tue, 10 Oct 2023 18:18:05 +0000 (18:18 +0000)
committeranton <anton@openbsd.org>
Tue, 10 Oct 2023 18:18:05 +0000 (18:18 +0000)
pipe_read().

regress/sys/kern/pipe/test-kqueue.c

index ede5bc9..f13015f 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: test-kqueue.c,v 1.4 2021/10/22 05:03:57 anton Exp $   */
+/*     $OpenBSD: test-kqueue.c,v 1.5 2023/10/10 18:18:05 anton Exp $   */
 
 /*
  * Copyright (c) 2019 Anton Lindqvist <anton@openbsd.org>
@@ -137,6 +137,8 @@ test_kqueue_write(void)
                n = read(ctx.c_pipe[0], &c, 1);
                if (n == -1)
                        err(1, "read");
+               if (n == 0)
+                       break;
                if (n != 1)
                        errx(1, "read: %ld != 1", n);
        }
@@ -296,5 +298,7 @@ kqueue_thread(void *arg)
        ctx->c_alive = 0;
        ctx_unlock(ctx);
 
+       close(fd);
+
        return NULL;
 }