Software Transactional Memory
페이지 정보
작성자 WI 작성일25-11-30 00:18 (수정:25-11-30 00:18)관련링크
본문
In laptop science, software program transactional memory (STM) is a concurrency management mechanism analogous to database transactions for controlling entry to shared memory in concurrent computing. It is an alternate to lock-primarily based synchronization. STM is a method carried out in software program, fairly than as a hardware part. A transaction in this context happens when a bit of code executes a series of reads and writes to shared memory. These reads and writes logically occur at a single instantaneous in time; intermediate states usually are not seen to other (successful) transactions. The concept of offering hardware help for transactions originated in a 1986 paper by Tom Knight. The thought was popularized by Maurice Herlihy and J. Eliot B. Moss. In 1995, Nir Shavit and Dan Touitou prolonged this idea to software program-solely transactional Memory Wave App (STM). Unlike the locking strategies utilized in most trendy multithreaded functions, STM is usually very optimistic: a thread completes modifications to shared memory without regard for what different threads might be doing, recording every read and write that it's performing in a log.
As an alternative of inserting the onus on the writer to make sure it does not adversely affect different operations in progress, it is positioned on the reader, who after completing an entire transaction verifies that other threads haven't concurrently made modifications to memory that it accessed prior to now. This last operation, in which the adjustments of a transaction are validated and, if validation is successful, made permanent, is called a commit. A transaction can also abort at any time, inflicting all of its prior changes to be rolled back or undone. If a transaction can't be dedicated as a result of conflicting adjustments, it is typically aborted and Memory Wave App re-executed from the beginning till it succeeds. The good thing about this optimistic approach is elevated concurrency: no thread must anticipate entry to a useful resource, and completely different threads can safely and simultaneously modify disjoint elements of an information construction that may usually be protected under the identical lock.
Nevertheless, in apply, STM methods additionally undergo a efficiency hit compared to wonderful-grained lock-primarily based techniques on small numbers of processors (1 to four relying on the applying). This is due primarily to the overhead associated with sustaining the log and the time spent committing transactions. Even in this case efficiency is often no worse than twice as sluggish. Advocates of STM believe this penalty is justified by the conceptual advantages of STM. Theoretically, the worst case space and time complexity of n concurrent transactions is O(n). Actual wants rely upon implementation details (one can make transactions fail early enough to avoid overhead), however there'll also be cases, albeit uncommon, the place lock-based mostly algorithms have better time complexity than software program transactional memory. STM drastically simplifies conceptual understanding of multithreaded applications and helps make packages extra maintainable by working in harmony with present high-level abstractions akin to objects and modules. Locking requires fascinated with overlapping operations and partial operations in distantly separated and seemingly unrelated sections of code, a process which may be very troublesome and error-prone.
Locking requires programmers to undertake a locking coverage to stop deadlock, livelock, and different failures to make progress. Such policies are sometimes informally enforced and fallible, and when these issues come up they are insidiously tough to reproduce and debug. Locking can result in priority inversion, a phenomenon the place a excessive-precedence thread is pressured to look forward to a low-precedence thread holding exclusive entry to a useful resource that it wants. In distinction, the idea of a memory transaction is far easier, because each transaction might be viewed in isolation as a single-threaded computation. Deadlock and livelock are both prevented solely or dealt with by an external transaction manager; the programmer want hardly worry about it. Priority inversion can nonetheless be a problem, however high-precedence transactions can abort conflicting decrease priority transactions that have not already committed. Nonetheless, the need to retry and abort transactions limits their habits. Any operation performed within a transaction must be idempotent since a transaction is likely to be retried. Additionally, if an operation has unwanted side effects that have to be undone if the transaction is aborted, then a corresponding rollback operation should be included.
This makes many input/output (I/O) operations difficult or unattainable to carry out inside transactions. Such limits are sometimes overcome in observe by creating buffers that queue up the irreversible operations and carry out them after the transaction succeeds. In Haskell, this limit is enforced at compile time by the type system. In 2005, Tim Harris, Simon Marlow, Simon Peyton Jones, and Maurice Herlihy described an STM system built on Concurrent Haskell that allows arbitrary atomic operations to be composed into larger atomic operations, a helpful concept not possible with lock-based mostly programming. For example, consider a hash desk with thread-secure insert and delete operations. Now suppose that we wish to delete one item A from table t1, and insert it into desk t2; but the intermediate state (wherein neither desk comprises the item) should not be seen to other threads. Until the implementor of the hash table anticipates this want, there is simply no way to fulfill this requirement. In brief, operations which might be individually correct (insert, delete) cannot be composed into larger right operations.
댓글목록
등록된 댓글이 없습니다.

