|Skip Navigation Links|
|Exit Print View|
|Multithreaded Programming Guide Oracle Solaris 11.1 Information Library|
This chapter describes the synchronization types that are available with threads. The chapter also discusses when and how to use synchronization.
Synchronization objects are variables in memory that you access just like data. Threads in different processes can communicate with each other through synchronization objects that are placed in threads-controlled shared memory. The threads can communicate with each other even though the threads in different processes are generally invisible to each other.
Synchronization objects can also be placed in files. The synchronization objects can have lifetimes beyond the life of the creating process.
The available types of synchronization objects are
Situations that can benefit from the use of synchronization include the following:
Synchronization is the only way to ensure consistency of shared data.
Threads in two or more processes can use a single synchronization object jointly. Because reinitializing a synchronization object sets the object to the unlocked state, the synchronization object should be initialized by only one of the cooperating processes.
Synchronization can ensure the safety of mutable data.
A process can map a file and direct a thread in this process get a record's lock. Once the lock is acquired, any thread in any process mapping the file attempting to acquire the lock is blocked until the lock is released.
Accessing a single primitive variable, such as an integer, can use more than one memory cycle for a single memory load. More than one memory cycle is used where the integer is not aligned to the bus data width or is larger than the data width. While integer misalignment cannot happen on the SPARC architecture, portable programs cannot rely on the proper alignment.