There are a series of strategies that may be employed to solve these problems, depending on what you want to accomplish and what tools you'll be using (e.g. application framework libraries). The most common solution to all of these problems is thread synchronization.
Thread synchronization is the art of forcing one thread to wait until another thread finishes a specific task.
It is common to utilize synchronization objects to ensure that methods are thread-safe. Synchronization objects allow threads to coordinate with one another.
Whenever an object's state information is accessed, you must ensure that the state will not be corrupted if the thread is interrupted and another object then accesses the object's state. Without synchronization, you cannot predict or control when a thread will be interrupted. To recap, an object is thread-safe if it cannot be corrupted in being accessed by multiple threads (or processes).
Synchronization objects provide mutually exclusive access to objects, so that only one thread at a time may access that object. The details of their implementation are operating system and development framework specific, but they all accomplish the same thing; they say, "One at a time, boys," to each of your threads.