add readwritelock
but the segment problem still persists