CSC 456 Fall 2013/7a ac: Difference between revisions
Line 44: | Line 44: | ||
===Semaphores and Mutexes=== | ===Semaphores and Mutexes=== | ||
Semaphores are simple data types used for controlling access to variables. They classically have two operations, wait() and signal(), sometimes known as acquire() and release(). There are two types of semaphores, binary semaphores and counting semaphores. Binary semaphores can only hold a value of 0 or 1, basically meaning that only one thread can access the semaphore at a time. Counting semaphores can have any number of resource instances. A mutex is essentially a binary semaphore with a few extra safety features that make them more desirable to use than plain semaphores. | Semaphores are simple data types used for controlling access to variables. They classically have two operations, wait() and signal(), sometimes known as acquire() and release(). There are two types of semaphores, binary semaphores and counting semaphores. Binary semaphores can only hold a value of 0 or 1, basically meaning that only one thread can access the semaphore at a time. Counting semaphores can have any number of resource instances. A mutex is essentially a binary semaphore with a few extra safety features that make them more desirable to use than plain semaphores.<ref name="semaphore"/> | ||
===Monitors=== | ===Monitors=== |
Revision as of 04:15, 19 November 2013
Survey of Primitives for Synchronization
Assignment
7a. Survey of primitives for synchronization Section 7.3 of Solihin covers the need for synchronization at the program level. It mentions lock and unlock operations. But real programs do not usually call lock and unlock mechanisms. Instead, they use higher-level operations, such as Java’s synchronized statement, or Open MP pragmas. Consider popular languages and common OSs such as Linux, MacOS, and Windows. How would programs do synchronization in these environments?
Ideas
synchronization constucts
syncs in clr semaphores in monitors (how many langs available in?)
Different Synchronization Constructs, languages that support them, general info.
Test-and-Set
Test-and-Test-and-Set
Lock-free
Array-lock
Semaphore-Java, C Acquire/Release the semaphore to enter the critical section. Only 1 thread can have the semaphore at a time.
Mutex-Java, C Like a binary semaphore, but with a few differences such as deletion safety (a process holding a mutex cannot be deleted).
Monitor-Java, C
Synchronized-Java
pragma-C (OpenMP)
a study of behavior of synchronization methods in commonly used languages and systems cederman et al.
Types of Synchronization
Locks
A lock is a synchronization mechanism for enforcing limits on access to a resource in an environment where there are many threads of execution. A lock is designed to enforce a mutual exclusion concurrency control policy.<ref name="lock"/> There are several different implementations of locks, as well as higher level constructs that use them, which will be briefly examined below.
Semaphores and Mutexes
Semaphores are simple data types used for controlling access to variables. They classically have two operations, wait() and signal(), sometimes known as acquire() and release(). There are two types of semaphores, binary semaphores and counting semaphores. Binary semaphores can only hold a value of 0 or 1, basically meaning that only one thread can access the semaphore at a time. Counting semaphores can have any number of resource instances. A mutex is essentially a binary semaphore with a few extra safety features that make them more desirable to use than plain semaphores.<ref name="semaphore"/>
Monitors
According to Wikipedia, a monitor is "a thread-safe class, object, or module that uses wrapped mutual exclusion in order to transparently safely be used by more than one thread."<ref name="monitor"/>
Supported Synchronization in Different Languages
The following table shows different programming languages and their support for various synchronization methods. The cells are color coded based on the following key:
None | Windows Only | Mac Only | Linux Only | Windows & Mac | Windows & Linux | Mac & Linux | All |
Language | Semaphore/Mutex | Monitor | OpenMP | Synchronized | Other |
---|---|---|---|---|---|
C | |||||
Java | |||||
C++ | Slim Rd/Wr Lock (SRW) | ||||
C# | |||||
Ruby | Get Sources | ||||
Python | Get Sources | ||||
PHP | Get Sources | ||||
Fortran | Co-Array<ref name="coarray"/> |
References
<references> <ref name="monitor">Monitor (synchronization)</ref> <ref name="coarray">Co-Array Fortran</ref> </references>