fixed an unsynchronized bug

Though (it seems that) fseek() and fread() operations are both
internally thread-safe, nothing is guaranteed when they are combined. So
it's necessary to put combined Seek+Read or Seek+Write operations in a
critical section.