{"id":250,"date":"2015-07-17T00:46:34","date_gmt":"2015-07-16T16:46:34","guid":{"rendered":"http:\/\/www.olinone.com\/?p=250"},"modified":"2015-12-01T14:55:02","modified_gmt":"2015-12-01T06:55:02","slug":"ios%e5%bc%80%e5%8f%91%e5%a4%9a%e7%ba%bf%e7%a8%8b%e5%90%8c%e6%ad%a5","status":"publish","type":"post","link":"http:\/\/www.olinone.com\/?p=250","title":{"rendered":"iOS\u5f00\u53d1\u591a\u7ebf\u7a0b\u540c\u6b65"},"content":{"rendered":"<address>\u8f6c\u8f7d\u8bf7\u6ce8\u660e\u51fa\u5904:<a href=\"http:\/\/www.olinone.com\/\">http:\/\/www.olinone.com\/<\/a><\/address>\n<p>Hi\uff0c\u4eca\u5929\u8ddf\u5927\u5bb6\u804a\u804aiOS\u5f00\u53d1\u4e2d\u591a\u7ebf\u7a0b\u540c\u6b65\u7684\u8bdd\u9898\u3002\u8bf4\u5230\u591a\u7ebf\u7a0b\u540c\u6b65\uff0c\u5404\u4f4d\u7ae5\u978b\u53ef\u80fd\u7acb\u523b\u4f1a\u60f3\u5230NSLock\u3001NSCondtion\u751a\u81f3OSSpinLock\u7b49\u7b49\u5404\u79cd\u7ebf\u7a0b\u9501\u3002\u4f46\u662f\uff0c\u4eca\u5929\u6211\u4eec\u4e0d\u8c08\u7ebf\u7a0b\u9501\uff0c\u5404\u4f4d\u5982\u679c\u5bf9Lock\u6709\u5174\u8da3\uff0c\u53ef\u4ee5\u770b\u770b\u8fd9\u7bc7<a href=\"http:\/\/ksnowlv.github.io\/blog\/2014\/09\/07\/ios-tong-bu-suo-xing-neng-dui-bi\/\">\u6587\u7ae0<\/a>\uff0c\u65e2\u7136\u4e0d\u8c08\u7ebf\u7a0b\u9501\uff0c\u90a3\u8bf4\u5565\uff1f\u5f53\u7136\u662f\u8bf4\u591a\u7ebf\u7a0b\u540c\u6b65<\/p>\n<p>\u7ebf\u7a0b\u540c\u6b65\u4e0d\u7b49\u4e8e\u7ebf\u7a0b\u9501\u3002\u8981\u89e3\u51b3\u540c\u6b65\u95ee\u9898\uff0c\u9996\u5148\u9700\u8981\u4e86\u89e3\u4e3a\u4ec0\u4e48\u9700\u8981\u7ebf\u7a0b\u540c\u6b65\uff0c\u7ebf\u7a0b\u4e0d\u540c\u6b65\u4e3b\u8981\u539f\u56e0\u5728\u4e8e\u591a\u4e2a\u7ebf\u7a0b\u53ef\u80fd\u540c\u65f6\u64cd\u4f5c\u67d0\u4e2a\u5bf9\u8c61\u4ece\u800c\u5bfc\u81f4\u72b6\u6001\u4e0d\u4e00\u81f4\u7684\u95ee\u9898\u3002\u662f\u4e0d\u662f\u53ef\u4ee5\u8fd9\u4e48\u7406\u89e3\uff0c\u5982\u679c\u591a\u7ebf\u7a0b\u4e0d\u4f1a\u540c\u4e00\u65f6\u523b\u8bbf\u95ee\u5bf9\u8c61\u5c31\u89e3\u51b3\u4e86\u540c\u6b65\u95ee\u9898\u3002\u5982\u4f55\u505a\u5230\u8fd9\u4e00\u70b9\uff1f\u53ef\u4ee5\u91c7\u7528<strong>\u4e32\u884c\u961f\u5217\u7684\u601d\u60f3\uff0c<\/strong>\u4f55\u4e3a\u4e32\u884c\u961f\u5217\uff1f\u53ef\u4ee5\u7b80\u5355\u7406\u89e3\u4e3a\u6240\u6709\u64cd\u4f5c\u90fd\u5fc5\u987b\u6309\u987a\u5e8f\u4f9d\u6b21\u6267\u884c\u3002\u4e3b\u7ebf\u7a0b\u5c31\u662f\u4e32\u884c\u961f\u5217\uff0c\u6700\u7b80\u5355\u7684\u540c\u6b65\u65b9\u5f0f\u5c31\u662f\u628a\u540c\u6b65\u64cd\u4f5c\u653e\u5230\u4e3b\u7ebf\u7a0b\u6267\u884c\uff0c\u7136\u5e76\u5375\uff0c\u5f53\u6211\u6ca1\u8bf4<\/p>\n<p>\u65e2\u7136\u4e0d\u80fd\u5728\u4e3b\u7ebf\u7a0b\u6267\u884c\uff0c\u653e\u5230\u5b50\u7ebf\u7a0b\u4e0d\u5c31OK\uff1f\u521b\u5efa\u5b50\u7ebf\u7a0b\u7684\u65b9\u5f0f\u6709\u5f88\u591a\uff0c\u4e0d\u7d2f\u8ff0\uff0c\u6709\u5174\u8da3\u7684\u7ae5\u978b\u53ef\u4ee5\u5404\u663e\u795e\u901a<\/p>\n<h3>GCD\u540c\u6b65<\/h3>\n<p>GCD\u53ef\u80fd\u662f\u521b\u5efa\u5b50\u7ebf\u7a0b\u6700\u7b80\u5355\u7684\u65b9\u5f0f\u4e4b\u4e00\uff0c\u5173\u4e8eGCD\uff0c\u8fd9\u7bc7<a href=\"http:\/\/codingobjc.com\/blog\/2013\/05\/07\/gcdshi-yong-xiang-jie-shang-pian\/\">\u6587\u7ae0<\/a>\u505a\u4e86\u6bd4\u8f83\u8be6\u7ec6\u7684\u4ecb\u7ecd\uff0c\u4e0d\u518d\u8fdb\u4e00\u6b65\u63cf\u8ff0\u3002\u65e2\u7136\u8981\u5b9e\u73b0\u7ebf\u7a0b\u540c\u6b65\uff0c\u9996\u5148\u9700\u8981\u521b\u5efa\u4e32\u884c\u961f\u5217<\/p>\n<pre class=\"lang:objc highlight:0 decode:true\">_queue = dispatch_queue_create(\"com.olinone.synchronize.serialQueue\", NULL);\r\ndispatch_queue_t dQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0);\r\ndispatch_set_target_queue(_queue, dQueue);<\/pre>\n<p>\u7136\u540e\uff0c\u5c06\u6240\u6709\u540c\u6b65\u4e8b\u4ef6\u4f9d\u6b21\u52a0\u5165\u961f\u5217\u4e2d\u5373\u53ef\u786e\u4fdd\u591a\u7ebf\u7a0b\u540c\u6b65<\/p>\n<pre class=\"lang:objc highlight:0 decode:true\">dispatch_async(_queue, ^{\r\n    block();\r\n});<\/pre>\n<h3>\u00a0NSOperationQueue\u540c\u6b65<\/h3>\n<p>\u901a\u8fc7GCD\u7684\u65b9\u5f0f\u5373\u53ef\u6ee1\u8db3\u7edd\u5927\u591a\u6570\u9700\u6c42\uff0c\u4f46\u662f\u4e5f\u96be\u514d\u6709\u4e2a\u522b\u7279\u6b8a\u9700\u6c42\uff0c\u6bd4\u5982\u64cd\u4f5c\u7684\u53d6\u6d88\u3002\u6b64\u65f6\uff0cNSOperationQueue\u5c06\u662f\u4e0d\u9519\u7684\u9009\u62e9<\/p>\n<p>NSOperationQueue\u867d\u7136\u662f\u5e76\u53d1\u591a\u7ebf\u7a0b\u6c60\uff0c\u4f46\u662f\u5de7\u5999\u7684\u8bbe\u8ba1\u4e5f\u53ef\u4ee5\u8ba9\u5176\u5b9e\u73b0\u4e32\u884c\u961f\u5217\u7684\u529f\u80fd\u3002\u5f53maxConcurrentOperationCount=1\u7684\u65f6\u5019\uff0c\u540c\u4e00\u65f6\u523b\u53ea\u6709\u4e00\u4e2aNSOperation\u88ab\u6267\u884c\uff0cNSOperationQueue\u5c31\u7531\u5e76\u53d1\u6267\u884c\u53d8\u6210\u4e32\u884c\u6267\u884c<\/p>\n<pre class=\"lang:objc highlight:0 decode:true\">NSOperationQueue *operationQueue = [[NSOperationQueue alloc] init];\r\noperationQueue.maxConcurrentOperationCount  = 1;<\/pre>\n<p>\u5b9e\u73b0\u65b9\u5f0f\u4e0eGCD\u4e00\u6837\uff0c\u4f9d\u6b21\u5c06\u540c\u6b65\u64cd\u4f5c\u52a0\u5165\u5230\u7ebf\u7a0b\u6c60\u4e2d\u5373\u53ef\u5b9e\u73b0\u540c\u6b65\u64cd\u4f5c\u7684\u4e32\u884c\u6267\u884c<\/p>\n<pre class=\"lang:objc highlight:0 decode:true \">- (void)execSyncBlock:(void (^)())block {\r\n    if (NSOperationQueue.currentQueue == self) {\r\n        block();\r\n    } else {\r\n        NSBlockOperation *operation = [NSBlockOperation blockOperationWithBlock:block];\r\n        [self addOperations:@[operation] waitUntilFinished:YES];\r\n    }\r\n}<\/pre>\n<h4>\u00a0<a href=\"https:\/\/github.com\/panghaijiao\/HJSynchronizeDemo\">HJSynchronizeDemo<\/a>\u8be6\u7ec6\u5c55\u793a\u4e86\u5b9e\u9645\u4f7f\u7528\u65b9\u5f0f\u3002\u5de7\u5999\u7684\u5229\u7528\u4e32\u884c\u961f\u5217\u53ef\u4ee5\u5e26\u6765\u610f\u60f3\u4e0d\u5230\u7684\u6548\u679c\u3002\u9664\u4e86\u89e3\u51b3\u591a\u7ebf\u7a0b\u540c\u6b65\uff0c\u8fd8\u80fd\u591f\u5904\u7406\u4e32\u884c\u5f0f\u5927\u8ba1\u7b97\u7b49\u4e1a\u52a1\uff0c\u6bd4\u5982\u56fe\u7247\u6e32\u67d3\uff0c\u97f3\u9891\u5904\u7406\u7b49\u7b49<\/h4>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8f6c\u8f7d\u8bf7\u6ce8\u660e\u51fa\u5904:http:\/\/www.olinone.com\/ Hi\uff0c\u4eca\u5929\u8ddf\u5927\u5bb6\u804a\u804aiOS\u5f00\u53d1\u4e2d\u591a\u7ebf\u7a0b\u540c\u6b65\u7684\u8bdd\u2026 <span class=\"read-more\"><a href=\"http:\/\/www.olinone.com\/?p=250\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[7],"tags":[],"_links":{"self":[{"href":"http:\/\/www.olinone.com\/index.php?rest_route=\/wp\/v2\/posts\/250"}],"collection":[{"href":"http:\/\/www.olinone.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.olinone.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.olinone.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.olinone.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=250"}],"version-history":[{"count":24,"href":"http:\/\/www.olinone.com\/index.php?rest_route=\/wp\/v2\/posts\/250\/revisions"}],"predecessor-version":[{"id":380,"href":"http:\/\/www.olinone.com\/index.php?rest_route=\/wp\/v2\/posts\/250\/revisions\/380"}],"wp:attachment":[{"href":"http:\/\/www.olinone.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=250"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.olinone.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=250"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.olinone.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=250"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}