Reader writer using pthreads and java threads