What is OCM?

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:

Thread A
lock(account[i])
while(account[i]!=0){
account[i]--;
unlock(account[i]);
lock(account[i]);

}
unlock(account[i]);

Thread B
lock(account[j])
while(account[j]!=0){
account[j]--;
unlock(account[j]);
lock(account[j]);

}
unlock(account[j]);

OCM allows you to write safe parallel code like this:

Thread A
while(account[i]!=0){
account[i]--;
yield;

}

Thread B
while(account[j]!=0){
account[j]--;
yield;

}

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.
Syndicate content