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

Reply via email to