Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 15 Oct 2003 18:03:42 -0400 (EDT)
From:      Robert Watson <rwatson@FreeBSD.org>
To:        John Baldwin <jhb@FreeBSD.org>
Cc:        cvs-src@FreeBSD.org
Subject:   RE: cvs commit: src/sys/sys mutex.h
Message-ID:  <Pine.NEB.3.96L.1031015175545.54113J-100000@fledge.watson.org>
In-Reply-To: <XFMail.20031014170830.jhb@FreeBSD.org>

next in thread | previous in thread | raw e-mail | index | archive | help

On Tue, 14 Oct 2003, John Baldwin wrote:

> > I know it is racy in most contexts.  I use it to check to see if a thread
> > on the runq owns giant.  Since I have the sched lock it isn't racy but
> > even if it was it wouldn't matter in this case.
> 
> sched lock doesn't keep it from being racy.  Uncontested acquire and
> releases don't go anywhere near sched lock.  Are you checking a
> non-curthread thread pointer?  Maybe you could just do it for curthread
> and that would be enough for your heuristic, i.e. 
> 
>         if (thread == curthread && mtx_owned(&Giant)) {
>                 ... 
>         }
> 
> I'm just worried that if this is there someone is going to use it. :(

You mean like this?

while (mtx_trylock(&my_favorite_mtx)) {
	int gotthebastard;
	struct thread *td;
	struct proc *p;

	gotthebastard = 0;
	sx_slock(&allproc_lock);
	LIST_FOREACH(p, &allproc, p_list) {
		PROC_LOCK(p);
		FOREACH_THREAD_IN_PROC(p, td) {
			if (mtx_ownedby(&my_favorite_mtx, td)) {
				psignal(p, SIGKILL);
				gotthebastard = 1;
				break;
			}
		}
		PROC_UNLOCK(p);
		if (gotthebastard)
			break;
	}
	sx_sunlock(&allproc_lock);
	printf("Someone else owned the mutex, but I got the bastard\n");
}

Robert N M Watson             FreeBSD Core Team, TrustedBSD Projects
robert@fledge.watson.org      Network Associates Laboratories



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.NEB.3.96L.1031015175545.54113J-100000>