Observationally Cooperative Multithreading (OCM) is a model for parallel programming that attempts to to simplify the process of keeping track of possible thread interactions. Instead of using locks or atomic blocks to protect shared variables, OCM uses the simple semantics of uniprocessor cooperative multithreading, insisting that any changes made by some thread to shared data do not become known to other threads until it explicitly yields. As a result, all OCM code is serializable, which makes programs easier to reason about and debug. Programmers do not have to focus on explicitly locking every piece of shared data and are able to reason about their parallel programs sequentially.
Therefore, instead of writing safe parallel code like this:
OCM allows you to write safe parallel code like this:
Advantages of OCM
- OCM is serializable, which means an execution of an OCM program corresponds to some serial execution under uniprocessor cooperative multithreading.
- This makes the program easier for the programmer to reason about.
- The OCM system itself can be used as a debugging tool for parallel programs, since thread execution can be recorded and then replayed sequentially to easily reproduce rarely-occurring bugs.
- Code written using locks or more complicated systems like Software Transactional Memory are difficult to rewrite once they are written with explicit concurrency control statements. OCM is implementation-agnostic.
- This allows programmers to write parallel code before having to settle on a concurrency control method.
- It also provides a way to compare the performance of different concurrency control systems for research purposes.