On 03/10/2018 12:20 AM, John Hening wrote:
|

    executor =Executors.newFixedThreadPool(16);
while(true){
SocketChannelconnection =serverSocketChannel.accept();
        connection.configueBlocking(false);
        executor.execute(()->writeTask(connection));
}
voidwriteTask(SocketChannels){
        s.isBlocking();
}

publicfinalSelectableChannelconfigureBlocking(booleanblock)throwsIOException
{
synchronized(regLock){
...
            blocking =block;
}
returnthis;
}
|



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.


Reordered with what? Ordering is always between at least two data accesses.

If you figure out what "blocking" is protecting, you'll know whether you need a memory barrier or not.

--
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 mechanical-sympathy+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to