{"id":288881,"date":"2021-01-17T04:06:34","date_gmt":"2021-01-16T20:06:34","guid":{"rendered":"http:\/\/4563.org\/?p=288881"},"modified":"2021-01-17T04:06:34","modified_gmt":"2021-01-16T20:06:34","slug":"lock-%e6%8c%87%e4%bb%a4%e5%88%b0%e5%ba%95%e6%9c%89%e4%bb%80%e4%b9%88%e7%94%a8%ef%bc%9f","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=288881","title":{"rendered":"Lock \u6307\u4ee4\u5230\u5e95\u6709\u4ec0\u4e48\u7528\uff1f"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  Lock \u6307\u4ee4\u5230\u5e95\u6709\u4ec0\u4e48\u7528\uff1f               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Orlion <\/span>  <span><i><\/i> 0<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u6700\u8fd1\u5728\u770b\u539f\u5b50\u64cd\u4f5c\u7684\u539f\u7406\uff0c\u5f97\u77e5\u662f\u901a\u8fc7 Lock \u6307\u4ee4\u4fdd\u8bc1\u4e86\u5185\u5b58\u8bfb\u5199\u539f\u5b50\u6027\uff0c\u5176\u539f\u7406\u662f<\/p>\n<ul>\n<li>CPU \u4fdd\u8bc1 Lock \u540e\u7f00\u540e\u8ddf\u7684\u6307\u4ee4\u539f\u5b50\u6027<\/li>\n<li>\u8001 CPU \u4e0a\u901a\u8fc7\u9501\u603b\u7ebf\u6765\u4fdd\u8bc1\u53ef\u89c1\u6027<\/li>\n<li>\u65b0 CPU \u4e0a\u5982\u679c\u6570\u636e\u5b58\u5728\u4e8e cpu cache \u4e0a\u65f6\u901a\u8fc7 MESI \u534f\u8bae\u6765\u5b9e\u73b0\u53ef\u89c1\u6027\uff0c\u5426\u5219\u8fd8\u662f\u9501\u603b\u7ebf<\/li>\n<\/ul>\n<p>\u5bf9\u6b64\u6211\u4ea7\u751f\u4e86\u51e0\u4e2a\u95ee\u9898\uff1a<\/p>\n<ol>\n<li>\u96be\u9053\u4e0d\u58f0\u660e Lock CPU \u5c31\u4e0d\u901a\u8fc7 MESI \u534f\u8bae\u4fdd\u8bc1 cache \u4e00\u81f4\u6027\u5417\uff1f\u6211\u89c9\u5f97\u4e0d\u662f, https:\/\/strikefreedom.top\/cpu-caches-theory-and-application \u8fd9\u7bc7\u6587\u7ae0\u7684 demo \u4e2d\u5e76\u6ca1\u6709\u58f0\u660e Lock \u6307\u4ee4\uff0c\u4f46\u4ecd\u7136\u51fa\u73b0\u4e86\u7f13\u5b58\u5931\u6548\u3002<\/li>\n<li>\u662f\u4e0d\u662f\u9664\u4e86 cpu cache \u5916\u8fd8\u6709 store buffer \u548c invalid queue \u4f1a\u5f71\u54cd\u53ef\u89c1\u6027\uff0c\u6240\u4ee5 CPU \u53ea\u80fd\u4fdd\u8bc1 cache \u7684\u4e00\u81f4\u6027\u4f46\u4fdd\u8bc1\u4e0d\u4e86\u5176\u4ed6\u786c\u4ef6\u7f13\u5b58\u5c42\u9762\u7684\u4e00\u81f4\u6027\uff0c\u6240\u4ee5\u8fd8\u662f\u9700\u8981 Lock \u6307\u4ee4\uff1f<\/li>\n<\/ol><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>7<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"4966293\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Jooooooooo <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             MESI \u6211\u7406\u89e3\u4fdd\u8bc1\u7684\u662f L1, L2 cache \u4e0a\u7684\u4e00\u81f4\u6027\u5427, \u5bf9\u4e8e cpu \u5bc4\u5b58\u5668\u4e2d\u7684\u503c\u4e0d\u4fdd\u8bc1.                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4966294\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : Orlion <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @Jooooooooo lock \u4e0e\u5bc4\u5b58\u5668\u65e0\u5173                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4966295\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : yzbythesea <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             Lock \u662f\u4e00\u4e2a prefix\uff0c\u5c31\u662f\u6307\u5b9a\u63a5\u4e0b\u6765\u7684 instruction \u4e00\u5b9a\u662f\u539f\u5b50\u64cd\u4f5c\u7684\u3002Lock \u53ea\u80fd\u548c\u6781\u5c11\u6570\u6307\u4ee4\u4e00\u8d77\u4f7f\u7528\uff0c\u901a\u5e38\u662f read-modify-write\uff0c\u6bd4\u5982 INCL(i)\uff0c\u5c31\u662f i = i + 1 \u3002\u5728 Lock \u6307\u4ee4\u6267\u884c\u7684\u65f6\u5019\uff0cCPU \u5bf9\u4e8e\u8fd9\u4e2a cache line \u6709\u7edd\u5bf9\u63a7\u5236\u6743\uff0c\u4e0d\u4f1a\u5171\u4eab\u7ed9\u5176\u4ed6 CPU \u3002\u4f60\u4e0d\u7528 Lock\uff0cCPU \u4e0d\u4f1a\u4fdd\u8bc1\u8be5 cache line \u53ea\u6709\u4ed6\u80fd\u7528\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4966296\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : Orlion <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @yzbythesea CPU \u64cd\u4f5c L3 cache \u4e0a\u540c\u4e00\u4e2a cacheline \u540c\u4e00\u4f4d\u7f6e\u6570\u636e\uff0c\u4e0d\u52a0 Lock \u5c31\u4e0d\u662f\u539f\u5b50\u7684\uff0c\u8fd9\u6837\u7406\u89e3\u5417\uff1f\u5982\u679c\u4e0d\u52a0 Lock \u4e5f\u662f\u539f\u5b50\u7684\uff0c\u90a3 CPU \u6ca1\u5fc5\u8981\u9501\u5427                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4966297\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : yzbythesea <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u662f\u554a cache \u90fd\u662f CPU \u5171\u4eab\u7684 \u9664\u975e\u4f60\u662f\u5355\u6838                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4966298\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : yzbythesea <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8fd9\u4e2a\u8981\u770b\u4f60\u662f\u4ec0\u4e48\u64cd\u4f5c \u6bd4\u5982 \u8bfb\uff0c\u80af\u5b9a\u662f\u539f\u5b50\u554a\uff0c\u6240\u4ee5 Lock \u4e0d\u80fd\u7528\u4e8e\u8fd9\u4e2a\u6307\u4ee4                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4966299\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : Orlion <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @yzbythesea \u611f\u8c22\u63d0\u9192\uff0c\u7a81\u7136\u610f\u8bc6\u5230\u4e86                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>Lock \u6307\u4ee4\u5230\u5e95\u6709\u4ec0\u4e48\u7528\uff1f \u8cc7\u6df1&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/288881"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=288881"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/288881\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=288881"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=288881"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=288881"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}