{"id":28114,"date":"2020-02-12T16:01:07","date_gmt":"2020-02-12T21:01:07","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=28114"},"modified":"2020-02-11T16:28:01","modified_gmt":"2020-02-11T21:28:01","slug":"kvo-reentrancy-canary","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2020\/02\/12\/kvo-reentrancy-canary\/","title":{"rendered":"KVO Reentrancy Canary"},"content":{"rendered":"<p><a href=\"https:\/\/medium.com\/@Kentzo\/reentrancy-and-same-stack-race-conditions-25cf4fb37846\">Ilya Kulakov<\/a> (<a href=\"https:\/\/twitter.com\/Kentzo\/status\/1220816794111266816\">tweet<\/a>):<\/p>\n<blockquote cite=\"https:\/\/medium.com\/@Kentzo\/reentrancy-and-same-stack-race-conditions-25cf4fb37846\"><p>While possibility of race conditions in the multithreaded code is a side effect of the desired behavior when multiple processing units compute result based on the shared data, Same-Stack Race Conditions are outright incorrect.<\/p><p><a href=\"https:\/\/developer.apple.com\/library\/archive\/documentation\/Cocoa\/Conceptual\/KeyValueCoding\/index.html\">KVO<\/a>, while often a hated victim, is not the only troubled technology. Everything that uses same-stack callbacks, including <a href=\"https:\/\/developer.apple.com\/library\/archive\/documentation\/General\/Conceptual\/CocoaEncyclopedia\/DelegatesandDataSources\/DelegatesandDataSources.html\">Delegates<\/a> and <a href=\"https:\/\/developer.apple.com\/library\/archive\/documentation\/General\/Conceptual\/DevPedia-CocoaCore\/Notification.html\">Notifications<\/a>, is susceptible.<\/p>\n<p>[&#8230;]<\/p>\n<p>In Objective-C and Cocoa I use the following lock-like approach that relies on RAII scopes (and relatively &ldquo;modern&rdquo; Clang and GCC that support the <code class=\"gz ha hb hc hd b\">cleanup<\/code> attribute) to detect the errors[&#8230;]<\/p><\/blockquote>\n\n<p>Previously:<\/p>\n<ul>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2020\/01\/10\/kvo-my-enemy\/\">KVO, My Enemy<\/a><\/li>\n<\/ul>","protected":false},"excerpt":{"rendered":"<p>Ilya Kulakov (tweet): While possibility of race conditions in the multithreaded code is a side effect of the desired behavior when multiple processing units compute result based on the shared data, Same-Stack Race Conditions are outright incorrect.KVO, while often a hated victim, is not the only troubled technology. Everything that uses same-stack callbacks, including Delegates [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"2020-02-11T21:27:37Z","apple_news_api_id":"9df2476c-8476-4438-9fb7-6dffdc3d261c","apple_news_api_modified_at":"2020-02-12T21:02:21Z","apple_news_api_revision":"AAAAAAAAAAAAAAAAAAAAAA==","apple_news_api_share_url":"https:\/\/apple.news\/AnfJHbIR2RDift23_3D0mHA","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[4],"tags":[69,31,1667,275,30,1666,54,74,71],"class_list":["post-28114","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-cocoa","tag-ios","tag-ios-13","tag-keyvalueobserving","tag-mac","tag-macos-10-15","tag-objective-c","tag-opensource","tag-programming"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/28114","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=28114"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/28114\/revisions"}],"predecessor-version":[{"id":28115,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/28114\/revisions\/28115"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=28114"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=28114"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=28114"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}