Re: Code review request: small optimization to localtime.c
- From: "M. Warner Losh" <imp@xxxxxxxxxx>
- Date: Sun, 16 Dec 2007 19:16:41 -0700 (MST)
In message: <20071204085502.N83722@xxxxxxxxxxxxxxxxxxxxxxx>
Jan Grant <jan.grant@xxxxxxxxxxxxx> writes:
: On Mon, 3 Dec 2007, Alfred Perlstein wrote:
:
: [on the double-checked locking idiom]
:
: > Karsten, _typically_ (but not always) an "unlock" operation
: > requires that writes prior to the unlock be globally visible.
: >
: > This is why it works almost everywhere.
:
: Perhaps, but if you use it you should probably mark the code with
: /* XXX not guaranteed to be correct by POSIX */
:
: Double-checked locking is broken without an appropriate barrier.
: "Correctness over speed" should surely be our watchword :-)
Actually, the code I posted for review *IS* posixly correct.
It doesn't matter if the write posts or not. If it doesn't post, then
we know the guard variable will be false still and we take out the
lock, test it see that it is true (since nothing would work well if
the lock/unlock pairs didn't force a consistent variable after the
lock is released). If it is posted, we don't take the branch.
Since these variables are initialized to zero and set exactly once to
true, the above is true.
pthread_once() is more optimal, but a larger code change.
Warner
_______________________________________________
freebsd-arch@xxxxxxxxxxx mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-arch
To unsubscribe, send any mail to "freebsd-arch-unsubscribe@xxxxxxxxxxx"
- Follow-Ups:
- Re: Code review request: small optimization to localtime.c
- From: Bruce Evans
- Re: Code review request: small optimization to localtime.c
- References:
- Re: Code review request: small optimization to localtime.c
- From: Karsten Behrmann
- Re: Code review request: small optimization to localtime.c
- From: Alfred Perlstein
- Re: Code review request: small optimization to localtime.c
- From: Jan Grant
- Re: Code review request: small optimization to localtime.c
- Prev by Date: Re: pending changes for TOE support
- Next by Date: Re: Added native socks support to libc in FreeBSD 7
- Previous by thread: Re: Code review request: small optimization to localtime.c
- Next by thread: Re: Code review request: small optimization to localtime.c
- Index(es):
Relevant Pages
|
|