Puzzled about turnstile's lock
guomingyan at gmail.com
Sat Dec 17 19:19:57 PST 2005
On 12/18/05, rookie <asmrookie at gmail.com> wrote:
> Hi hackers,
> > I want to understand the current implementation of
> > turnstile,and meet some questions about its locks' logicality.
> It's used to lock td_contested member of struct thread structure and all
> issues linked to it (as you can see in the source tree). It seems used in a
> clean way.
> turnstile's ``ts_blocked" field is protected by both
> > ``td_contested" lock and its turnstile_chain lock, but
> > I think its turnstile_chain lock is enough,because we
> > allways get the turnstile_chain lock before our manipulation
> > on ``ts_blocked".
> > If td_contested lock were needed ,reading ts_blocked is
> > not protected by td_contested lock,in the kernel source, why?
> > Thanks.
> > --
> > Three passions, simple but overwhelmingly strong, have governed my life:
> > the longing for love, the search for knowledge, and unbearable pity for
> > the suffering of mankind.
> > ---------Bertrand Russell
> > _______________________________________________
> > freebsd-hackers at freebsd.org mailing list
> > http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
> > To unsubscribe, send any mail to "
> > freebsd-hackers-unsubscribe at freebsd.org"
> Peace can only be achieved by understanding - A. Einstein
Thanks,I think I get it now.As mentioned in arch-handbook
You can protect a datum with multiple locks.
Then for reading that data you simply need
to have a read lock of one of the locks.
However, to write to the data, you need to
have a write lock of all of the locks
We also can read "ts_blocked" if only td_contested
lock is held,but this way is not needed now.
Three passions, simple but overwhelmingly strong, have governed my life:
the longing for love, the search for knowledge, and unbearable pity for
the suffering of mankind.
More information about the freebsd-hackers