Forum Stats

  • 3,854,501 Users
  • 2,264,372 Discussions
  • 7,905,707 Comments

Discussions

Selector wakeup() and "happens-before"

user5636127
user5636127 Member Posts: 1
edited Sep 27, 2015 3:17AM in Networking

Greetings,

I have the following question regarding NIO, say if I have:

* Thread-1

// Memory write to a non-volatile variable

var = X;

selector.wakeup();

* Thread-2

selector.select();

// Memory read from a non-volatile variable

anotherVar = var;

The question is will it work or I eventually have to make the variable volatile? I.e. does selector.wakeup() establish happens-before relationship?

Thanks.

Answers

  • EJP
    EJP Member Posts: 32,920 Gold Crown
    edited Sep 27, 2015 3:17AM

    Not unless it is so specified in the JVM Specification, which it almost certainly isn't. Arbitrary APIs don't affect the memory model, only the ones so specified in the JVM Spec, and they are very few in number.

This discussion has been closed.