Re: Code review request: small optimization to localtime.c



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"



Relevant Pages

  • Re: Locking subforms
    ... I lock the prior months depending on the current date. ... If I set the allowedits to true or false, will that unlock the fields I just ...
    (microsoft.public.access.setupconfig)
  • Re: Refresh Problem
    ... If I wait 3 seconds between mouse clicks on the lock / unlock button, ... workstation is looking at a current copy of the data. ... MESSAGEBOX statement after all of the database lookups have been done ...
    (microsoft.public.fox.programmer.exchange)
  • Re: A scoped lock/unlock implementation in C++.
    ... mutex_locker wrapping the same mutex, more than one thread won't share ... But beyond that it will still work with thread local mutex_locker instances, since no two threads can have a nonzero lock count anyway. ... When entering a locked region, if the last entry is negative, you know ... In case of unlocks even the unlock count is insignificant. ...
    (comp.programming.threads)
  • Re: [PATCH] Remove softlockup from invalidate_mapping_pages.
    ... These block devices are very likely to have just one ... Being locked for read is very unlikely because mdadm would have already ... memory reclaim could lock the page, ... core is free to unlock the page when the IO completes, ...
    (Linux-Kernel)
  • Re: Why are Boost thread mutexes so slow compared to Pthreads?
    ... Don't let unlock() happen automatically for unexpected throws ... ENOTRECOVERABLE returned on subsequent lock()) to expose corruption. ... A thrown exception may not be a fatal error per se, ... There's no reason why this function ...
    (comp.programming.threads)