Fixes a race problem on close and also a JMM violation.

the isClosed isn't volatile an there is no other synchronization mechanism; so it can safely be used in a multithreaded environment.

Also the close method itself is racy if multiple threads at the same time call close.