Below, we quote a function for managing a transaction in a hypothetical transaction management system. It is very likely multiple instances of the function to be executed in parallel on a system of symmetric multiprocessing (SMP), on multi-processor platforms or even a multithreaded single processor systems.

To avoid possible race conditions and deadlocks, we should protect the critical region of the function (code that acts on shared resources). If this protection is not done, it is very likely that the behavior of the transaction management system will be unstable and the transaction insecure.

Below, we use the function pthread_setcancelstate() which protects the critical region of the function so as to prevent both its interruption (atomic execution) and the parallel execution of multiple instances (within the critical region).

The secure function of the hypothetical Transaction Management System follows:

#include <pthread.h>

int
process_transaction (int from_account, int to_account, float euro) {
  int old_cancel_state;

  ... // init inline stuff.

  /* begin critical section. */
  pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, &old_cancel_state);

  ... // handle the resources.

  /* end critical section. */
  pthread_setcancelstate (old_cancel_state, NULL);

  ... // return something.
}