public class TestAtomicIncrement
{
int j;
public TestAtomicIncrement()
{
j = 10;
}
public static void main(String[] args)
throws Exception
{
TestAtomicIncrement tai = new TestAtomicIncrement();
tai.j++;
int i = 10;
i++;
}
}
[EMAIL PROTECTED] small-tests]$ javac TestAtomicIncrement.java
[EMAIL PROTECTED] small-tests]$ javap -c TestAtomicIncrement
Compiled from TestAtomicIncrement.java
public class TestAtomicIncrement extends java.lang.Object {
int j;
public TestAtomicIncrement();
public static void main(java.lang.String[]) throws
java.lang.Exception;
}
Method TestAtomicIncrement()
0 aload_0
1 invokespecial #1 <Method java.lang.Object()>
4 aload_0
5 bipush 10
7 putfield #2 <Field int j>
10 return
Method void main(java.lang.String[])
0 new #3 <Class TestAtomicIncrement>
3 dup
4 invokespecial #4 <Method TestAtomicIncrement()>
7 astore_1
8 aload_1
9 dup
10 getfield #2 <Field int j>
13 iconst_1
14 iadd
15 putfield #2 <Field int j>
18 bipush 10
20 istore_2
21 iinc 2 1
24 return
I think the getfield bytecode is supposed to implemented in such a way
that it is atomic for an int field. It is possible the putfield
bytecode is as well, i don't know the jls that well. But it is doubtful
that the method#'s 10-15 comprise an atomic operation.
john mcnally
On Wed, 2003-08-13 at 12:32, David Graham wrote:
> --- Dirk Verbeeck <[EMAIL PROTECTED]> wrote:
> > The pool manipulation was synchronized, only the isEmpty() test is not.
> > I didn't realize that _numActive++ should be synchronized, I thought the
> >
> > ++ operator was atomic.
>
> The datatype the operator is applied to is what matters. Assignments to
> ints are atomic, assignments to longs aren't because they are 64 bits.
> So, if _numActive is an int, I don't think it needs to be synchronized.
>
> David
>
> > I'll put these also in a synchronized block.
> >
> >
> http://cvs.apache.org/viewcvs/jakarta-commons/pool/src/java/org/apache/commons/pool/impl/GenericObjectPool.java?rev=1.23&content-type=text/vnd.viewcvs-markup
> >
> > How does this new version looks?
> >
> > Dirk
> >
> > John McNally wrote:
> >
> > >My quick read of this change is not favorable. It looks like changes
> > to
> > >an unsynchronized list have been moved outside any synchronization.
> > >Also integer math like numActive++ outside a synchronization block has
> > >got me into problems in the past. A test with two threads using i++
> > and
> > >i-- ran quite some time (couple hours) on a single processor box, but
> > >did eventually fail. Then the test was run on a dual processor box, it
> > >failed pretty much immediately, repeatedly.
> > >
> > >I'm -1 on this change.
> > >
> > >john mcnally
> > >
> > >
> >
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
>
>
> __________________________________
> Do you Yahoo!?
> Yahoo! SiteBuilder - Free, easy-to-use web site design software
> http://sitebuilder.yahoo.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]