The least intrusive way to guarantee serial access to a shared resource is to associate a semaphore with it, and to acquire ownership of the semaphore before accessing the resource. The application threads will be suspended only when there is actual contention for the resource.
This does require all of the programmers involved to be careful to request the semaphore before accessing the resource, and to remember to free it when done. The classic solution to this is to build a low-level function which includes the serialization.
Semaphores are of three categories:
They are the System Semaphore, the RamSem, and the FastSafe RamSem, which is an accounting structure prefixed onto a RamSem.