pthread: implement reader/writer lock