Explain how multi-threading works in C++ and how you would prevent race conditions in a high-throughput environment.