one question on mutex.

John Baldwin jhb at freebsd.org
Mon Oct 3 17:46:29 UTC 2011


On Monday, September 26, 2011 10:37:32 am satish kondapalli wrote:
> I declared one test mutex  in my char module:
> struct mtx test_mutex;
> 
> Initialized the above mutex while module loading:
> mtx_init(&test_mutex,"cdev_test_mutex",NULL,MTX_DEF);
> 
> and in charter device open() function I called mtx_lock() twice. 
> mtx_lock(&test_mutex);
> mtx_lock(&test_mutex);
> 
> Here my question is why the kernel is not blocking on second call of
> mtx_lock() ?
> Here i initilaized my mutex type as MTX_DEF. All default MTX_DEF are
> recursive? (then what is MTX_RECURSE ).

If you have INVARIANTS on, it will panic if you do not have MTX_RECURSE set.
However, mutexes are all effectively recursive.

-- 
John Baldwin


More information about the freebsd-drivers mailing list