Synchronization techniques among threads

When you create code that is threadsafe but still benefits from sharing data or resources between threads, the most important aspect of programming becomes the ability to synchronize threads.

Synchronization is the cooperative act of two or more threads that ensures that each thread reaches a known point of operation in relationship to other threads before continuing. Attempting to share resources without correctly using synchronization is the most common cause of damage to application data.

Typically, synchronizing two threads involves the use of one or more synchronization primitives. Synchronization primitives are low-level functions or application objects (not i5/OS™ objects) that your application used or created to provide the synchronization behavior the application requires.

The most common synchronization primitives are as follows, in order of least to most computationally expensive:

These concepts pertain to all programming languages. To determine how each language enables these concepts, refer to the Language topic in the information center for the specific language.

Related concepts
Suspend a thread
Function calls that are not thread safe