Source-Changes-HG archive

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

[src/trunk]: src/tests/rump/kernspace Fix a race condition on taking the mutex



details:   https://anonhg.NetBSD.org/src/rev/f6c78f9f313d
branches:  trunk
changeset: 828702:f6c78f9f313d
user:      ozaki-r <ozaki-r%NetBSD.org@localhost>
date:      Thu Dec 28 04:38:02 2017 +0000

description:
Fix a race condition on taking the mutex

The workqueue worker can take the mutex before the tester tries to take it after
calling workqueue_enqueue. If it happens, the worker calls cv_broadcast before
the tester calls cv_timedwait and the tester will wait until the cv timed out

Take the mutex before calling workqueue_enqueue so that the tester surely calls
cv_timedwait before the worker calls cv_broadcast.

The fix stabilizes the test, t_workqueue/workqueue1.

diffstat:

 tests/rump/kernspace/workqueue.c |  6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diffs (28 lines):

diff -r a52098988d38 -r f6c78f9f313d tests/rump/kernspace/workqueue.c
--- a/tests/rump/kernspace/workqueue.c  Thu Dec 28 04:36:15 2017 +0000
+++ b/tests/rump/kernspace/workqueue.c  Thu Dec 28 04:38:02 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: workqueue.c,v 1.2 2017/12/28 04:36:15 ozaki-r Exp $    */
+/*     $NetBSD: workqueue.c,v 1.3 2017/12/28 04:38:02 ozaki-r Exp $    */
 
 /*-
  * Copyright (c) 2017 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
 
 #include <sys/cdefs.h>
 #if !defined(lint)
-__RCSID("$NetBSD: workqueue.c,v 1.2 2017/12/28 04:36:15 ozaki-r Exp $");
+__RCSID("$NetBSD: workqueue.c,v 1.3 2017/12/28 04:38:02 ozaki-r Exp $");
 #endif /* !lint */
 
 #include <sys/param.h>
@@ -84,8 +84,8 @@
 #define ITERATIONS 12435
        for (size_t i = 0; i < ITERATIONS; ++i) {
                int e;
+               mutex_enter(&sc->mtx);
                workqueue_enqueue(sc->wq, &sc->wk, NULL);
-               mutex_enter(&sc->mtx);
                e = cv_timedwait(&sc->cv, &sc->mtx, hz * 2);
                if (e != 0)
                        panic("cv_timedwait timed out (i=%lu)", i);



Home | Main Index | Thread Index | Old Index