Date: Tue, 31 Jan 2012 06:35:08 -0500 From: <dmitry.krivenok@emc.com> To: <freebsd-hackers@freebsd.org> Subject: mtx_trylock() on a spin mutex Message-ID: <9C7BACB01B839A499792154E76C9ADE5563FDD39ED@MX19A.corp.emc.com>
next in thread | raw e-mail | index | archive | help
Hello, Could someone please explain why mtx_trylock() must not be called on a spin= mutex? Is it conceptually wrong or is it a restriction of FreeBSD kernel implement= ation? I've written slightly modified version of mtx_trylock (mtx_trylock_spin) wh= ich calls=20 spinlock_enter/spinlock_exit and doesn't have KASSERT checking for lock cla= ss: KASSERT(m->mtx_object.lo_class =3D=3D &lock_class_mtx_sleep, ("mtx_trylock() of spin mutex %s @ %s:%d", m->mtx_object.= lo_name, file, line)); but, to my surprise, all my tests passed w/o any errors/warnings on FreeBSD= -8 with WITNESS/INVARIANTS/etc enabled. I admit that my tests may not cover all possible use cases or scenarios tho= ugh. I did a quick google search but didn't find anything useful, so your help i= s greatly appreciated. Thanks in advance! P.S. The assertion was added in the following revision: Revision 149737 - (view) (annotate) - [select for diffs]=20 Modified Fri Sep 2 20:21:49 2005 UTC (6 years, 4 months ago) by jhb=20 File length: 24623 byte(s)=20 Diff to previous 148557=20 - Add an assertion to panic if one tries to call mtx_trylock() on a spin mutex. - Don't panic if a spin lock is held too long inside _mtx_lock_spin() if panicstr is set (meaning that we are already in a panic). Just keep spinning forever instead.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?9C7BACB01B839A499792154E76C9ADE5563FDD39ED>