ReentrantReadWriteLock understanding
Hi,
I am studying the mechanism of readLock() and writeLock() but is still hazy on them even read through the java.util.concurrent.locks API doc many times. I have encountered the following questions:
1. As I know the writeLock() is actually holding up a lock whereas readLock() doesn't; so why not simply using synchronized instead of readLock() if only implementing a thread-safe block?
2. Extend the above question, can a write thread place a lock on a share object while a reader thread has already held up a lock on the object and is processing some operations within the readLock block?
3. Can I say that the main purpose of readLock, other than polled, timed, and interruptible lock acquisition, is to guarantee memory visibility?
4. Is there any pre-defined preferences for readLock() or writeLock() acquisition?
5. According to Peter Haggar's article, Double-checked locking and the singleton pattern, http://www.ibm.com/developerworks/java/library/j-dcl.html,
even a modifed version of double-checked locking trying to prevent the out-of-order write problem:-
publicstatic Singleton getInstance()
{
if (instance ==null)
{
synchronized(Singleton.class){
Singleton inst = instance;
if (inst ==null)
{
synchronized(Singleton.class){
inst =new Singleton();
}
instance = inst;
}
}
}
return instance;
}
but double-checked locking is still no guarantee on single processor or multi-processors. Is this solved on the newly depolyed JVM?
I would be appreciated if I can have your input; if possible, could you suggest any material for my further reading?
Thanks in advance

