Fixing possible race conditions in iostreams component