You know...something seemed odd about it, but I was going to go with it anyway...I'm still pretty sure that an increment operation is not atomic, but I can't be sure.
Regardless, the example statement given in the original post was something like: x = y++; And I'm almost 100% certain that's not atomic, as the increment of y and assignment to x are two separate operations. -----Original Message----- From: Larry Sandereson [mailto:[EMAIL PROTECTED]] Sent: Thursday, July 18, 2002 9:32 AM To: [EMAIL PROTECTED] Subject: Re: [JBoss-dev] is x++ an atomic operation?? The jguru article is not accurate. Given the code: public class Test { public int testInc(int x) { x++; return x; } public int testAdd(int x) { x = x + 1; return x; } } This produces the following byte-code: Method Test() 0 aload_0 1 invokespecial #1 <Method java.lang.Object()> 4 return Method int testInc(int) 0 iinc 1 1 3 iload_1 4 ireturn Method int testAdd(int) 0 iload_1 1 iconst_1 2 iadd 3 istore_1 4 iload_1 5 ireturn Note the single operation for the incrementor (iinc 1 1). I do not know if this operation is atomic or not, but this invalidates the logic of the jguru post. -Larry ----- Original Message ----- From: "Rhett Aultman" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Thursday, July 18, 2002 6:24 AM Subject: RE: [JBoss-dev] is x++ an atomic operation?? I'm fairly sure that the increment/decrement operators are not atomic. Hm...here's a post on Jguru showing why: http://www.jguru.com/forums/view.jsp?EID=384082 Additionally, I think the statement that you gave in your example would be non-atomic anyway- even if an increment was atomic, you're first performing the increment, then storing it in a second variable. That's a two-step process, regardless of atomicity in the increment. -----Original Message----- From: Hiram Chirino [mailto:[EMAIL PROTECTED]] Sent: Thursday, July 18, 2002 8:55 AM To: [EMAIL PROTECTED] Subject: [JBoss-dev] is x++ an atomic operation?? Quick question for you Java Language Gurus out there, I heard one that the post increment operator was an atomic operation. For example, if you have a multi-threaded application with: id=lastRequestId++; You would not need to put this in a synchronized block be cause the ++ would be atomic and thus you would not get 2 duplicate ids. I was wondering if this is true or not. Can anybody confirm this for me?? Regards, Hiram ------------------------------------------------------- This sf.net email is sponsored by:ThinkGeek Welcome to geek heaven. http://thinkgeek.com/sf _______________________________________________ Jboss-development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-development ------------------------------------------------------- This sf.net email is sponsored by:ThinkGeek Welcome to geek heaven. http://thinkgeek.com/sf _______________________________________________ Jboss-development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-development ------------------------------------------------------- This sf.net email is sponsored by:ThinkGeek Welcome to geek heaven. http://thinkgeek.com/sf _______________________________________________ Jboss-development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-development ------------------------------------------------------- This sf.net email is sponsored by:ThinkGeek Welcome to geek heaven. http://thinkgeek.com/sf _______________________________________________ Jboss-development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-development