Implementing Mutual Exclusion Algorithm by Burns and Lynch in Java: Could there be issues due to instruction reordering?

前端 未结 1 551
情歌与酒
情歌与酒 2021-01-26 07:43

I found a fairly simple n-process mutual exclusion algorithm on page 4 (836) in the following paper:
          \"Mutual Exc

1条回答
  •  故里飘歌
    2021-01-26 08:09

    In the java memory model you have no guarantee that a write to F[i] will be visible to another Thread reading from it later.

    The standard solution for this kind of visibility problem is to declare the shared variable as volatile, but in this case F is an array and write/reads to F[i] do not change the value of F.

    It is not possible to declare an "array of volatiles ...", but one can declare F as AtomicIntegerArray and use compareAndSet to atomically change the array content without worrying about Thread-visibility.

    0 讨论(0)
提交回复
热议问题