>
> That (t1 always see the same value of x when x is modified elsewhere) is
> possible, e.g. in a tight loop reading x and nothing else
>
And this is why I dislike when people say: "volatile field" ensures you
*only* about ordering. It is not true. Because it also means:
Mr javac/java/jit,
I synchronized access to that object so please be careful during reoderding
*AND* and optimization like: (Java perspective) I don't load the value from
the memory because noone can modify it (because it is not
volatile/synchronized- I have no clue that object is shared!)
Gil, thanks for your explanation.
W dniu piątek, 9 marca 2018 23:20:37 UTC+1 użytkownik John Hening napisał:
>
>
> executor = Executors.newFixedThreadPool(16);
> while(true) {
> SocketChannel connection = serverSocketChannel.accept();
> connection.configueBlocking(false);
> executor.execute(() -> writeTask(connection));
> }
> void writeTask(SocketChannel s){
> s.isBlocking();
> }
>
> public final SelectableChannel configureBlocking(boolean block) throws
> IOException
> {
> synchronized (regLock) {
> ...
> blocking = block;
> }
> return this;
> }
>
>
>
> We see the following situation: the main thread is setting
> connection.configueBlocking(false)
>
> and another thread (launched by executor) is reading that. So, it looks
> like a datarace.
>
> My question is:
>
> 1. Here
> configureBlocking
>
> is synchronized so it behaves as memory barrier. It means that code is ok-
> even if reading/writing to
> blocking
>
> field is not synchronized- reading/writing boolean is atomic.
>
> 2. What if
> configureBlocking
>
> wouldn't be synchronized? What in a such situation? I think that it would
> be necessary to emit a memory barrier because it is theoretically possible
> that setting blocking field could be reordered.
>
> Am I right?
>
--
You received this message because you are subscribed to the Google Groups
"mechanical-sympathy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.