印第安人属于什么人种| 暴饮暴食容易得什么病| 3月21日是什么星座| 什么的味道| 天才是指什么生肖| 降血糖的草都有什么草| 贫血吃什么可以补血| horns是什么意思| 暖寿是什么意思| 梦见包饺子是什么征兆| 抠脚大汉什么意思| 纹身有什么危害| cdc是什么| 高兴的什么| 虫草治什么病| 肩胛骨疼痛挂什么科| 行李箱什么材质的好| 放疗后吃什么恢复的快| 脐带绕颈有什么症状| 皮笑肉不笑是什么生肖| 女人严重口臭挂什么科| 做梦梦到屎什么意思| gg是什么意思| 拎不清是什么意思| 吊膀子是什么意思| 吃什么清理脑血管堵塞| 生性凉薄什么意思| 什么满天下| 柳树的叶子像什么| 再接再厉是什么意思| 猪蹄炖什么好吃| 猎头是干什么的| 每天早上起床口苦是什么原因| ac什么意思| 子宫内膜炎有什么症状| 女人眼角有痣代表什么| 扑朔迷离什么意思| 心电图pr间期缩短是什么意思| 办慢性病有什么好处| 献血有什么危害| 儿童包皮挂什么科| 什么是元素| 红细胞阳性是什么意思| 破瓦法是什么| 农历今天属什么| 啤酒和什么不能一起吃| 手机壳什么材质好| 紫气东来什么意思| 比熊吃什么牌子的狗粮好| 赞聊是什么意思| 痛经吃什么水果| 白板是什么意思| 梦见大水是什么意思| 紫萱名字的含义是什么| 教唆什么意思| 口腔溃疡是什么| 胃反酸水吃什么药| 睡眠不好吃什么| 周文王叫什么| 头七有什么规矩| 什么的东风填词语| 6月20号什么星座| 1993属什么| 马非读什么| 6代表什么| 黄帝内经是什么时期的| 手心长痣代表什么| 古代警察叫什么| 八月十五是什么节日| 驻马店以前叫什么名字| 飞机票号是什么意思| 7月30日是什么日子| 痤疮用什么药治最好效果最快| 女性肛裂要抹什么药好| 反复口腔溃疡是什么病的前兆| 药学是干什么的| 拉泡沫稀便什么原因| 鹿茸有什么功效| 猿人头是什么牌子| 粉玫瑰代表什么| 因果报应是什么意思| 碘伏是什么| 为什么前壁容易生男孩| 21三体综合征是指什么| 微创手术是什么意思| 双手脱皮是什么原因引起的| 处女座和什么星座最配| 螺旋杆菌阳性是什么病| 6月26日是什么日子| 拘禁是什么意思| 十月初一是什么节| 防蓝光是什么意思| 前列腺液是什么样子| 地奥司明片治疗什么病| 土中金是什么生肖| 色弱是什么| 脾湿热吃什么中成药| 膨鱼鳃用什么搭配煲汤| 息肉吃什么药可以消掉| 总想小便是什么原因| 肾衰透析病人吃什么好| 白带是什么| 四方八面是什么生肖| 南红五行属什么| 小猫感冒吃什么药| 翡翠a货是什么意思| 尿多是什么原因女性| 吃什么盐好| 维生素b9是什么| 睡觉爱流口水是什么原因| 咲是什么意思| 什么叫眼睛散光| 朝鲜钱币叫什么| 泡脚对身体有什么好处| 开塞露是干什么用的| 儿童乐园有什么好玩的| 农历六月十七是什么星座| 临终关怀的目的是什么| 什么叫化疗| 痛风能吃什么鱼| 孕妇吃什么盐最好| 熟地黄是什么| 动物的耳朵有什么作用| 荨麻疹长什么样图片| 冷暖自知上一句是什么| 擅长是什么意思| 蜗牛有什么特点| 什么星座最疼射手座| 孕吐吃什么药| 温存是什么意思| 什么是白噪音| 港澳通行证办理需要什么证件| 密度单位是什么| 胆囊壁增厚是什么意思| 胸口正中间疼是什么病| 梦见吃蜂蜜是什么预兆| 什么门永远关不上| 口缘字一半念什么| 补充b族维生素有什么好处| 怎么是什么意思| hpv是什么病毒| 猫咪喜欢什么颜色| 三点水加亘念什么| 手上的线分别代表什么图解| 心病有什么症状| 柿子什么时候成熟| 胳膊脱臼是什么症状| 调兵遣将是什么生肖| 素肉是什么| 蝶变是什么意思| 偏光镜什么意思| 白芷长什么样图片| 什么原因引起脑梗| 考教师编制需要什么条件| 蕈是什么意思| 画蛇添足什么意思| 有冬瓜西瓜南瓜为什么没有北瓜| 指甲白色是什么原因| 橘子是什么季节的水果| 网络cp是什么意思| 荔枝不能与什么一起吃| 人参归脾丸和归脾丸有什么区别| 月黑风高什么意思| 荷尔蒙爆棚是什么意思| 突然耳朵聋是什么原因| 蓝色配什么色好看| 大林木是什么数字| 发烧腿疼是什么原因| lxy是什么意思| 俄罗斯为什么要打乌克兰| 全身发黄是什么原因| 空调外机风扇不转是什么原因| 早泄有什么办法| 瘦人吃什么能长胖| 脸上长毛什么原因| 咽喉痛吃什么药| 二月二十二日是什么星座| 大便出血吃什么药| ca125是什么检查项目| 为什么女人阴唇会变黑| 为什么脸上老长痘痘| 男人头发硬说明什么| 12月什么星座| 什么是包皮过长图片| 最近老放屁是什么原因| 八髎区疼是什么原因| 肌酐高是什么原因造成的| noisy是什么意思| 欲钱看正月初一是什么生肖| 四库是指什么| jeep是什么牌子| 陶土色大便是什么颜色| 浪琴名匠系列什么档次| 粘米粉可以做什么好吃的| 三岁宝宝喝什么奶粉比较好| 口羊读什么| 满文军现在在干什么| 梦见自己家盖房子是什么预兆| 尿酸降低是什么意思| 什么叫不动产| 吃什么水果容易排便| 贤良淑德后半句是什么| 看喉咙挂什么科| 故人是什么意思| 野生葛根粉有什么功效| 愚蠢是什么意思| 长长的柳条像什么| 什么时候减肥效果最快最好| 签证和护照有什么区别| 绍兴有什么大学| 拆台是什么意思| 今天忌什么宜什么| 矫枉过正是什么意思| 春考是什么| 放化疗是什么意思| 水煮肉片放什么配菜| 酒糟鼻买什么药膏去红| yn是什么牌子| 孔子是什么学派的创始人| 什么地飞翔| 什么鱼是深海鱼| 太岁是什么| 水母是什么动物| 心什么诚服| 什么全什么美| 淞字五行属什么| 兔肉不能和什么一起吃| 乌纱帽是什么意思| 疏忽是什么意思| 大便一粒粒的是什么原因| 为什么会连续两天遗精| 晚上梦见蛇是什么预兆| 兄长是什么意思| 口腔溃疡可以吃什么药| 冥冥中是什么意思| 执子之手与子偕老是什么意思| 清洁度iv是什么意思| 月球是地球的什么星| 二尾子什么意思| 肉毒为什么怕热敷| 什么人不能吃皮蛋| 空调除湿和制冷有什么区别| 理化检验主要检验什么| 土霉素治什么病| 什么时候长智齿| 398是什么意思| 李连杰是什么国籍| 子宫内膜16mm说明什么| 不眠夜是什么意思| 黄山毛峰属于什么茶| 女人吃猪肝有什么好处| 吃什么能增强免疫力| 1977年是什么命| 老烂腿用什么药最好| 竹外桃花三两枝的下一句是什么| 血压高不能吃什么| 95开头的是什么电话| 伸舌头锻炼有什么好处| 孩子肚脐眼下面疼是什么原因| 家里为什么会有蟑螂| 后脑勺白头发多是什么原因| 清关中是什么意思| 土和什么相生| konka是什么牌子| 百度Jump to content

秘鲁总统库琴斯基宣布辞职政局动荡难平

From Wikipedia, the free encyclopedia
百度 针对小鸣单车拖欠消费者押金、资金账户管理不规范等问题,去年年底,广东省消费者委员会向广州市中级人民法院提起消费民事公益诉讼。

In computer science, software transactional memory (STM) is a concurrency control mechanism analogous to database transactions for controlling access to shared memory in concurrent computing. It is an alternative to lock-based synchronization. STM is a strategy implemented in software, rather than as a hardware component. A transaction in this context occurs when a piece of code executes a series of reads and writes to shared memory. These reads and writes logically occur at a single instant in time; intermediate states are not visible to other (successful) transactions. The idea of providing hardware support for transactions originated in a 1986 paper by Tom Knight.[1] The idea was popularized by Maurice Herlihy and J. Eliot B. Moss.[2] In 1995, Nir Shavit and Dan Touitou extended this idea to software-only transactional memory (STM).[3] Since 2005, STM has been the focus of intense research[4] and support for practical implementations is growing.

Performance

[edit]

Unlike the locking techniques used in most modern multithreaded applications, STM is often very optimistic: a thread completes modifications to shared memory without regard for what other threads might be doing, recording every read and write that it is performing in a log. Instead of placing the onus on the writer to make sure it does not adversely affect other operations in progress, it is placed on the reader, who after completing an entire transaction verifies that other threads have not concurrently made changes to memory that it accessed in the past. This final operation, in which the changes of a transaction are validated and, if validation is successful, made permanent, is called a commit. A transaction may also abort at any time, causing all of its prior changes to be rolled back or undone. If a transaction cannot be committed due to conflicting changes, it is typically aborted and re-executed from the beginning until it succeeds.

The benefit of this optimistic approach is increased concurrency: no thread needs to wait for access to a resource, and different threads can safely and simultaneously modify disjoint parts of a data structure that would normally be protected under the same lock.

However, in practice, STM systems also suffer a performance hit compared to fine-grained lock-based systems on small numbers of processors (1 to 4 depending on the application). This is due primarily to the overhead associated with maintaining the log and the time spent committing transactions. Even in this case performance is typically no worse than twice as slow.[5] Advocates of STM believe this penalty is justified by the conceptual benefits of STM.[citation needed]

Theoretically, the worst case space and time complexity of n concurrent transactions is O(n). Actual needs depend on implementation details (one can make transactions fail early enough to avoid overhead), but there will also be cases, albeit rare, where lock-based algorithms have better time complexity than software transactional memory.

Conceptual advantages and disadvantages

[edit]

In addition to their performance benefits,[citation needed] STM greatly simplifies conceptual understanding of multithreaded programs and helps make programs more maintainable by working in harmony with existing high-level abstractions such as objects and modules. Lock-based programming has a number of well-known problems that frequently arise in practice:

  • Locking requires thinking about overlapping operations and partial operations in distantly separated and seemingly unrelated sections of code, a task which is very difficult and error-prone.
  • Locking requires programmers to adopt a locking policy to prevent deadlock, livelock, and other failures to make progress. Such policies are often informally enforced and fallible, and when these issues arise they are insidiously difficult to reproduce and debug.
  • Locking can lead to priority inversion, a phenomenon where a high-priority thread is forced to wait for a low-priority thread holding exclusive access to a resource that it needs.

In contrast, the concept of a memory transaction is much simpler, because each transaction can be viewed in isolation as a single-threaded computation. Deadlock and livelock are either prevented entirely or handled by an external transaction manager; the programmer need hardly worry about it. Priority inversion can still be an issue, but high-priority transactions can abort conflicting lower priority transactions that have not already committed.

However, the need to retry and abort transactions limits their behavior. Any operation performed within a transaction must be idempotent since a transaction might be retried. Additionally, if an operation has side effects that must be undone if the transaction is aborted, then a corresponding rollback operation must be included. This makes many input/output (I/O) operations difficult or impossible to perform within transactions. Such limits are typically overcome in practice by creating buffers that queue up the irreversible operations and perform them after the transaction succeeds. In Haskell, this limit is enforced at compile time by the type system.

Composable operations

[edit]

In 2005, Tim Harris, Simon Marlow, Simon Peyton Jones, and Maurice Herlihy described an STM system built on Concurrent Haskell that enables arbitrary atomic operations to be composed into larger atomic operations, a useful concept impossible with lock-based programming. To quote the authors:

Perhaps the most fundamental objection [...] is that lock-based programs do not compose: correct fragments may fail when combined. For example, consider a hash table with thread-safe insert and delete operations. Now suppose that we want to delete one item A from table t1, and insert it into table t2; but the intermediate state (in which neither table contains the item) must not be visible to other threads. Unless the implementor of the hash table anticipates this need, there is simply no way to satisfy this requirement. [...] In short, operations that are individually correct (insert, delete) cannot be composed into larger correct operations.
—Tim Harris et al., "Composable Memory Transactions", Section 2: Background, pg.2[6]

With STM, this problem is simple to solve: simply wrapping two operations in a transaction makes the combined operation atomic. The only sticking point is that it is unclear to the caller, who is unaware of the implementation details of the component methods, when it should attempt to re-execute the transaction if it fails. In response, the authors proposed a retry command which uses the transaction log generated by the failed transaction to determine which memory cells it read, and automatically retries the transaction when one of these cells is modified, based on the logic that the transaction will not behave differently until at least one such value is changed.

The authors also proposed a mechanism for composition of alternatives, the orElse function. It runs one transaction and, if that transaction does a retry, runs a second one. If both retry, it tries them both again as soon as a relevant change is made.[clarification needed] This facility, comparable to features such as the Portable Operating System Interface (POSIX) networking select() call, allows the caller to wait on any one of a number of events simultaneously. It also simplifies programming interfaces, for example by providing a simple mechanism to convert between blocking and nonblocking operations.

This scheme has been implemented in the Glasgow Haskell Compiler.

Proposed language support

[edit]

The conceptual simplicity of STMs enables them to be exposed to the programmer using relatively simple language syntax. Tim Harris and Keir Fraser's "Language Support for Lightweight Transactions" proposed the idea of using the classical conditional critical region (CCR) to represent transactions. In its simplest form, this is just an "atomic block", a block of code which logically occurs at a single instant:

// Insert a node into a doubly linked list atomically
atomic {
    newNode->prev = node;
    newNode->next = node->next;
    node->next->prev = newNode;
    node->next = newNode;
}

When the end of the block is reached, the transaction is committed if possible, or else aborted and retried. (This is simply a conceptual example, not correct code. For example, it behaves incorrectly if node is deleted from the list during the transaction.)

CCRs also permit a guard condition, which enables a transaction to wait until it has work to do:

atomic (queueSize > 0) {
    remove item from queue and use it
}

If the condition is not satisfied, the transaction manager will wait until another transaction has made a commit that affects the condition before retrying. This loose coupling between producers and consumers enhances modularity compared to explicit signaling between threads. "Composable Memory Transactions"[6] took this a step farther with its retry command (discussed above), which can, at any time, abort the transaction and wait until some value previously read by the transaction is modified before retrying. For example:

atomic {
    if (queueSize > 0) {
        remove item from queue and use it
    } else {
        retry
    }
}

This ability to retry dynamically late in the transaction simplifies the programming model and opens up new possibilities.

One issue is how exceptions behave when they propagate outside of transactions. In "Composable Memory Transactions",[6] the authors decided that this should abort the transaction, since exceptions normally indicate unexpected errors in Concurrent Haskell, but that the exception could retain information allocated by and read during the transaction for diagnostic purposes. They stress that other design decisions may be reasonable in other settings.

Transactional locking

[edit]

STM can be implemented as a lock-free algorithm or it can use locking.[7] There are two types of locking schemes: In encounter-time locking (Ennals, Saha, and Harris), memory writes are done by first temporarily acquiring a lock for a given location, writing the value directly, and logging it in the undo log. Commit-time locking locks memory locations only during the commit phase.

A commit-time scheme named "Transactional Locking II" implemented by Dice, Shalev, and Shavit uses a global version clock. Every transaction starts by reading the current value of the clock and storing it as the read-version. Then, on every read or write, the version of the particular memory location is compared to the read-version; and, if it is greater, the transaction is aborted. This guarantees that the code is executed on a consistent snapshot of memory. During commit, all write locations are locked, and version numbers of all read and write locations are re-checked. Finally, the global version clock is incremented, new write values from the log are written back to memory and stamped with the new clock version.

Implementation issues

[edit]

One problem with implementing software transactional memory with optimistic reading is that it is possible for an incomplete transaction to read inconsistent state (that is, to read a mixture of old and new values written by another transaction). Such a transaction is doomed to abort if it ever tries to commit, so this does not violate the consistency condition enforced by the transactional system, but it is possible for this "temporary" inconsistent state to cause a transaction to trigger a fatal exceptional condition such as a segmentation fault or even enter an endless loop, as in the following contrived example from Figure 4 of "Language Support for Lightweight Transactions":

atomic {
    if (x != y)
        while (true) { 
        }
}
atomic {
    x++;
    y++;
}
Transaction A
Transaction B

Provided x=y initially, neither transaction above alters this invariant, but it is possible that transaction A will read x after transaction B updates it but read y before transaction B updates it, causing it to enter an infinite loop. The usual strategy for dealing with this is to intercept any fatal exceptions and abort any transaction that is not valid.

One way to deal with these issues is to detect transactions that execute illegal operations or fail to terminate and abort them cleanly; another approach is the transactional locking scheme.

Practical implementations

[edit]

References

[edit]
  1. ^ "Wayback Machine" (PDF). web.mit.edu. Archived from the original (PDF) on 2025-08-05. Retrieved 2025-08-05.
  2. ^ Maurice Herlihy and J. Eliot B. Moss. Transactional memory: architectural support for lock-free data structures. Proceedings of the 20th annual international symposium on Computer architecture (ISCA '93). Volume 21, Issue 2, May 1993.
  3. ^ Nir Shavit and Dan Touitou. Software transactional memory. Distributed Computing. Volume 10, Number 2. February 1997.
  4. ^ ""software transactional memory" - Google Scholar". Retrieved 10 November 2013.
  5. ^ Peyton Jones, Simon. "Programming in the Age of Concurrency: Software Transactional Memory". Microsoft Developers Network: Channel 9. Retrieved 2025-08-05.
  6. ^ a b c Harris, T.; Marlow, S.; Peyton Jones, S.; Herlihy, M. (2005). "Composable memory transactions" (PDF). Proceedings of the tenth ACM SIGPLAN symposium on Principles and practice of parallel programming - PPoPP '05. p. 48. doi:10.1145/1065944.1065952. ISBN 1595930809. S2CID 53245159.
  7. ^ Concurrency_control#Methods
  8. ^ "Glasgow Haskell Compiler (GHC) Commentary: Software Transactional Memory (STM)". Haskell.org: GitLab.
  9. ^ "Software Transactional Memory in C++: Pure Functional Approach (tutorial)". GitHub.
  10. ^ "Refs and Transactions". Clojure.org.
  11. ^ "Poor man's STM in Node.js". Clojure.org.
  12. ^ "talhof8/kashmir". GitHub.
  13. ^ "Rust Package Registry". Crates.io.
  14. ^ "Introduction to Software Transactional Memory ZIO". Zio.dev.
  15. ^ "Kcas — STM based on lock-free MCAS". GitHub.
  16. ^ "Transactional memory (STM)". arrow-kt.io.
利可君片是治什么病 神经衰弱是什么意思 十二指肠球炎是什么病 晚八点是什么时辰 什么是龙骨
一什么木瓜 倒牙是什么意思 缺镁吃什么食物补充最快 长脸适合什么发型女 色达在四川什么地方
更年期皮肤瘙痒是什么原因 复方氨酚烷胺片是什么药 尿少尿黄是什么原因引起的 能吃是福是什么意思 莫逆是什么意思
张钧甯为什么读mi 什么能养肝 高血糖主食吃什么好 金牛属于什么象星座 甲状腺4a是什么意思
police是什么意思hcv7jop9ns9r.cn 骨加后念什么hcv8jop4ns3r.cn 三维彩超和四维彩超有什么区别yanzhenzixun.com 神经性皮炎不能吃什么食物hcv7jop9ns0r.cn 7月份什么星座cl108k.com
梦见洗手是什么意思wmyky.com 心脏彩超fs是什么意思hcv9jop6ns6r.cn 肺部斑片状高密度影是什么意思hcv9jop3ns8r.cn 长歌怀采薇是什么意思0297y7.com 吃什么清理脑血管堵塞hcv8jop3ns0r.cn
电动轮椅什么牌子质量好hcv8jop2ns7r.cn 白细胞加号什么意思hcv7jop9ns5r.cn 血糖的单位是什么clwhiglsz.com 生力军什么意思hcv7jop9ns3r.cn 蓝蓝的天上白云飘是什么歌hcv8jop0ns1r.cn
什么叫鳞状细胞mmeoe.com 上不下要读什么hcv8jop2ns2r.cn 陈醋与香醋有什么区别hcv9jop7ns1r.cn 带状疱疹一般长在什么地方hcv8jop3ns2r.cn 氧气湿化瓶里加什么水hcv9jop0ns7r.cn
百度