Explain the functions and system calls involved in multithreaded programming and how to prevent race conditions.