fix some bugs around locking writers and readers