How do you handle concurrency and race conditions when writing low-level multithreaded applications in C?