A thread safe c++ stream implementation