The Swift 5 release enables runtime checking of Exclusive Access to Memory by default in Release builds, further enhancing Swift’s capabilities as a safe language. These runtime checks were only enabled in Debug builds in Swift 4. Swift manages memory automatically and makes sure that multiple accesses to the same area of memory don’t conflict, by ensuring that the code that modifies the location in memory has exclusive access.
Memory access can be of two types:
- Read access
- Write access
Depending upon the duration of access, memory access is one of two types:
- Instantaneous access — the operation completes without any other code being able to interfere.
- Long-term access — the access spans the execution of other code. Usually happens when using
inout
arguments in functions or mutating methods of a structure.
Conflicts occur when there is long-term memory access. When the memory access is long-term it is possible for other code to modify or read the memory location, which is called overlap. Long-term access can overlap with other long-term accesses and instantaneous accesses. Exclusive memory access restricts the modification of the memory in case of overlap.
Exclusive access
Exclusive access restricts multiple simultaneous read/write operations or simultaneous write operations from happening in a memory location.
Comments
0 comments
Please sign in to leave a comment.