Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 11 Mar 2003 09:26:03 -0800 (PST)
From:      John Baldwin <jhb@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 26687 for review
Message-ID:  <200303111726.h2BHQ309059526@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=26687

Change 26687 by jhb@jhb_laptop on 2003/03/11 09:25:58

	Bah, I think my problem with kldunload was a race condition where
	the next thread destory event was posted before thread 1 had a
	chance to reacquire the event_mtx lock.  Instead, use a cv to
	close this race and similar races when sending events via the
	sysctl.  In evtest_postevent() we wait on this cv after we send
	an event and in event_thread() we signal this cv after setting
	event back to 0.  In thread_destroy() we wait on this cv only if
	the event is not zero after we resume from msleep().

Affected files ...

.. //depot/projects/smpng/sys/modules/evtest/evtest.c#11 edit

Differences ...

==== //depot/projects/smpng/sys/modules/evtest/evtest.c#11 (text+ko) ====

@@ -58,7 +58,7 @@
 #define	EVENT_TYPE_BROADCAST	0x1
 
 static eventhandler_tag first_tag;
-static struct cv event_cv, broadcast_cv;
+static struct cv event_cv, broadcast_cv, event_recvd;
 static struct mtx event_mtx;
 static struct sema evtest_sema;
 static int event, broadcast_count;
@@ -137,6 +137,7 @@
 		event = new_event;
 		cv_signal(&event_cv);
 	}
+	cv_wait(&event_recvd, &event_mtx);
 	mtx_unlock(&event_mtx);
 	return (0);
 }
@@ -245,6 +246,7 @@
 			}
 		}
 		event = 0;
+		cv_signal(&event_recvd);
 		while ((ev = event) == 0)
 			cv_wait(&event_cv, &event_mtx);
 		mtx_unlock(&event_mtx);
@@ -351,6 +353,8 @@
 	cv_broadcast(&event_cv);
 	msleep(threads[i].ti_p, &event_mtx, PWAIT, "evtstun", 0);
 	threads[i].ti_p = NULL;
+	if (event != 0)
+		cv_wait(&event_recvd, &event_mtx);
 }
 
 static void

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe p4-projects" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200303111726.h2BHQ309059526>