Date: Wed, 30 Jan 2008 20:52:04 +0000 From: John Birrell <jb@what-creek.com> To: John Baldwin <jhb@freebsd.org> Cc: Perforce Change Reviews <perforce@freebsd.org> Subject: Re: PERFORCE change 134245 for review Message-ID: <20080130205204.GA68541@what-creek.com> In-Reply-To: <200801300913.03782.jhb@freebsd.org> References: <200801272148.m0RLmWdF053919@repoman.freebsd.org> <200801300913.03782.jhb@freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, Jan 30, 2008 at 09:13:03AM -0500, John Baldwin wrote: > On Sunday 27 January 2008 04:48:32 pm John Birrell wrote: > > http://perforce.freebsd.org/chv.cgi?CH=134245 > > > > Change 134245 by jb@jb_freebsd1 on 2008/01/27 21:47:41 > > > > The linker lock here is private to code in this file. It is > > never a problem with it being locked when any other combination > > of locks are already obtained or even if *no* other locks are > > obtained. Use SX_NOWITNESS to avoid bogus LOR reports. > > If witness reports a LOR it is real, it may just not be obvious. Here is some code that demonstrates the problem: static struct mtx test_mtx; MTX_SYSINIT(test, &test_mtx, "Test", MTX_DEF); static int test_list(linker_file_t lf, void *arg) { printf("Linker file name: '%s'\n", lf->filename); return (0); } static void test_thread_func(void *arg) { printf("\n\nI'm a big bad thread, but I'm going to wait a bit... stay tuned...\n"); pause("Waiting a bit...", 5000); printf("The big bad thread is awake and he wants to list the linker files...\n"); linker_file_foreach(test_list, NULL); printf("Lock my wide scope mutex because I have stuff to protect...\n"); mtx_lock(&test_mtx); printf("I've done some stuff that my wide scope lock protected, but now I need to list some linker files...\n"); linker_file_foreach(test_list, NULL); printf("Unlock my wide scope mutex because I done what I needed to do...\n"); mtx_unlock(&test_mtx); printf("I'm done now.\n"); printf("====================\n"); kthread_exit(); } static int test_modevent(module_t mod __unused, int type, void *data __unused) { int error = 0; switch (type) { case MOD_LOAD: printf("--------------------\n"); printf("I am loaded! I can now list the linker files without grabbing any locks...\n"); linker_file_foreach(test_list, NULL); printf("OK, I'm done listing the linker files.\n"); printf("Now I'll create a thread to do some stuff after I've gone.\n"); kthread_add(test_thread_func, NULL, NULL, NULL, 0, 0, "testme"); printf("OK, the thread is created. I'm out of here.\n"); printf("--------------------\n"); break; case MOD_UNLOAD: printf("I am unloading!\n"); break; case MOD_SHUTDOWN: break; default: error = EOPNOTSUPP; break; } return (error); } DEV_MODULE(test, test_modevent, NULL); MODULE_VERSION(test, 1);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20080130205204.GA68541>