Call sched_yield() in Unsafe implementation
Andrew Haley
aph@redhat.com
Fri Nov 16 18:22:00 GMT 2007
In the fallback code in natUnsafe.cc -- which is used when gcc doesn't
support atomic builtins -- we don't yield when a lock is contended.
I've done a few experiments and on the machines I have it is always
much faster to yield the instant we realize a lock is held by another
thread. This may not be true for some high-end SMP boxes, but they
won't be calling this code.
Andrew.
2007-11-16 Andrew Haley <aph@redhat.com>
* sun/misc/natUnsafe.cc (spinlock contructor): Call sched_yield().
Index: sun/misc/natUnsafe.cc
===================================================================
--- sun/misc/natUnsafe.cc (revision 130234)
+++ sun/misc/natUnsafe.cc (working copy)
@@ -1,6 +1,6 @@
// natUnsafe.cc - Implementation of sun.misc.Unsafe native methods.
-/* Copyright (C) 2006
+/* Copyright (C) 2006, 2007
Free Software Foundation
This file is part of libgcj.
@@ -32,7 +32,7 @@
spinlock ()
{
while (! compare_and_swap (&lock, 0, 1))
- ;
+ _Jv_ThreadYield ();
}
~spinlock ()
{
--
Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SL4 1TE, UK
Registered in England and Wales No. 3798903
More information about the Java-patches
mailing list