You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hama.apache.org by "Edward J. Yoon (JIRA)" <ji...@apache.org> on 2015/08/28 15:17:45 UTC

[jira] [Commented] (HAMA-971) An increment to a volatile field isn't atomic

    [ https://issues.apache.org/jira/browse/HAMA-971?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14718544#comment-14718544 ] 

Edward J. Yoon commented on HAMA-971:
-------------------------------------

Hi, 

I looked at this code just now, and it seems that variables used within synchronized block. I'm not sure whether this guarantees write safety. 

{code}
synchronized (this) {
  ...
  ++checkpointMessageCount;
  ...
}
{code}


> An increment to a volatile field isn't atomic
> ---------------------------------------------
>
>                 Key: HAMA-971
>                 URL: https://issues.apache.org/jira/browse/HAMA-971
>             Project: Hama
>          Issue Type: Bug
>          Components: bsp core
>            Reporter: JongYoon Lim
>            Priority: Minor
>
> I found a defect from FindBugs Analysis.
> {code}
> // AsyncRcvdMsgCheckpointImpl.java
> volatile private long checkpointMessageCount;
> ...
> ++checkpointMessageCount;
> {code}
> {code}
> // Server.java
> private volatile int rpcCount = 0; // number of outstanding rpcs
> ...
> rpcCount--;
> rpcCount++;
> {code}
> This code increments a volatile field. Increments of volatile fields aren't atomic. If more than one thread is incrementing the field at the same time, increments could be lost.
> I think *AtomicInteger* and *AtomicLong* can be used instead of volatile fields. 



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)