Make TagInputStream and TagOutputStream thread safety.

Signed-off-by: yushijinhun <yushijinhun@gmail.com>