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

Reply via email to