Lock-Specific Memory Page Isolation for Thread Safety
Find Innovative SolutionsGenerate Solutions
Solution Overview
Problem
Concurrent programming is challenging due to interference between threads accessing and updating shared variables, as existing locking mechanisms do not ensure isolation, leading to issues like non-repeatable reads and dirty reads.
Innovation Solution
The method employs code instrumentation, data replication, and virtual memory protection to detect and prevent interference by creating a local copy of memory pages for locked variables, ensuring that only the owner thread can access and modify them, while other threads are delayed until the owner finishes, using an exception handler to enforce isolation.
Engineering Contradictions & Design Principles
Engineering Contradiction Analysis
1Reliability
If traditional locking mechanisms are used to protect shared variables, then thread safety is improved, but isolation between threads is not ensured, leading to interference issues
Solution Approach 1:
The patent segments the shared memory into lock-specific memory pages, where each lock has its own dedicated memory page. This segmentation isolates the data protected by each lock, preventing threads from accessing memory pages belonging to other locks without proper authorization, thereby ensuring both thread safety and isolation.
Solution Approach 2:
The patent introduces memory protection mechanisms as an intermediary layer between threads and shared variables. This intermediary enforces access rules by allowing only the owner thread to access its designated memory page while blocking other threads, thus preventing interference while maintaining thread safety.
2Object-affected harmful factors
If memory protection is enabled for all locked variables, then isolation is ensured, but access overhead increases due to exception handling
Solution Approach 1:
The patent applies memory protection selectively at the local level of individual lock-specific memory pages rather than globally across all shared memory. This allows the system to enable strong isolation guarantees only where needed (for locked variables) while maintaining efficient access for other memory operations, reducing overall overhead.
Solution Approach 2:
The patent performs preliminary actions by pre-allocating lock-specific memory pages and setting up protection mechanisms before threads access the protected variables. This preparation work is done in advance, so that when threads need to access locked variables, the isolation mechanism is already in place and can operate more efficiently without extensive setup overhead at access time.
3Speed
If local copies of memory pages are created for each thread, then access speed is improved, but memory consumption increases
Solution Approach 1:
The patent creates local copies of lock-specific memory pages in the address space of each thread that needs to access the protected variables. This copying mechanism allows threads to access their local copies directly without requiring frequent cross-page references, improving access speed while the lock-specific organization ensures that copies are made only when necessary.
Solution Approach 2:
The lock-specific memory pages serve multiple functions: they provide isolation boundaries, enable efficient access patterns, and support both read and write operations. This multi-functionality reduces the need for separate memory structures for different purposes, thereby optimizing memory consumption while maintaining access performance.
Data Source
AI summary
Locks are used to protect variables. All variables protected by a lock are allocated on a page associated with a lock. When a thread (called the owner) acquires the lock, a local copy of the memory page containing the variable is created, the original memory page is protected, and all access of the variable in the owner thread is directed to the local copy. Upon releasing the lock, the changes from the local copy are carried over to the memory page and the memory page is unprotected. Any concurrent access of the variable by non-owner threads triggers an exception handler (due to the protection mechanism) and delays such an access until after the owner thread has finished accessing the variable.


