[Return to Bookshelf] [Contents] [Previous Section] [Next Section] [Index] [Help]


3.2.3.1 DECthreads Global Lock

DECthreads provides a single global lock that can be used by all threads in a program when calling routines or code that is not thread-safe to ensure serialization and exclusivity of the unsafe code. You can acquire the global lock by calling pthread_ lock_global_np and unlock by calling pthread_unlock_global_np. The global lock allows a thread to acquire the lock recursively, so that you do not need to be concerned if you call a routine that also may acquire the global lock.

Because there is only one global lock, you do not need to fully analyze all of the dependencies in unsafe code that you call. With private locks to protect unsafe code, for example, one lock might protect calls to the stdio routine while another protects calls to math routines-but if stdio then calls a math routine without acquiring the math routine lock, the call is just as unsafe as if no locks were used.

Use the global lock whenever calling unsafe routines-and when unsure, always assume a routine is unsafe. All DECthreads routines are thread-safe.