{"id":15986,"date":"2016-10-07T14:41:56","date_gmt":"2016-10-07T18:41:56","guid":{"rendered":"http:\/\/mjtsai.com\/blog\/?p=15986"},"modified":"2023-01-27T14:54:42","modified_gmt":"2023-01-27T19:54:42","slug":"os_unfair_lock","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2016\/10\/07\/os_unfair_lock\/","title":{"rendered":"os_unfair_lock"},"content":{"rendered":"<p><a href=\"https:\/\/gist.github.com\/steipete\/36350a8a60693d440954b95ea6cbbafc\">Peter Steinberger<\/a> measured the new <code>os_unfair_lock<\/code> against <code>OSSpinLock<\/code>, <code>pthread_mutex<\/code>, <code>NSLock<\/code>, dispatch queues, and <code>@synchronized<\/code>.<\/p>\n<p><a href=\"https:\/\/twitter.com\/pedantcoder\/status\/743159748896268288\">Pierre Habouzit<\/a> (via <a href=\"https:\/\/twitter.com\/catfish_man\/status\/743252500728315905\">David Smith<\/a>):<\/p>\n<blockquote cite=\"https:\/\/twitter.com\/pedantcoder\/status\/743159748896268288\"><p>Apple&rsquo;s libplatform is now <a href=\"http:\/\/opensource.apple.com\/source\/libplatform\/libplatform-125\/\">OSS too<\/a> with user-land os_unfair_lock (os\/lock.c) in all its strict glory.<\/p><\/blockquote>\n<p><a href=\"https:\/\/twitter.com\/s_tolksdorf\/status\/783674065194221568\">Stephan Tolksdorf<\/a>:<\/p>\n<blockquote cite=\"https:\/\/twitter.com\/s_tolksdorf\/status\/783674065194221568\"><p> If you use it from Swift, you have to be careful, because it&rsquo;s a struct and Swift doesn&rsquo;t prevent you from copying or moving it around, which normally would be an error.<\/p><\/blockquote>\n<p>Previously: <a href=\"http:\/\/mjtsai.com\/blog\/2015\/12\/16\/osspinlock-is-unsafe\/\">OSSpinLock Is Unsafe<\/a>, <a href=\"http:\/\/mjtsai.com\/blog\/2016\/06\/07\/mutexes-and-closure-capture-in-swift\/\">Mutexes and Closure Capture in Swift<\/a>.<\/p>\n\n<p id=\"os_unfair_lock-update-2023-01-27\">Update (2023-01-27): <a href=\"https:\/\/cohost.org\/Catfish-Man\/post\/913314-a-love-letter-to-os\">David Smith<\/a>:<\/p>\n<blockquote cite=\"https:\/\/cohost.org\/Catfish-Man\/post\/913314-a-love-letter-to-os\"><p>A decade or so ago, &ldquo;what lock should I use?&rdquo; was a fairly complicated question on macOS\/iOS.<\/p><\/blockquote>","protected":false},"excerpt":{"rendered":"<p>Peter Steinberger measured the new os_unfair_lock against OSSpinLock, pthread_mutex, NSLock, dispatch queues, and @synchronized. Pierre Habouzit (via David Smith): Apple&rsquo;s libplatform is now OSS too with user-land os_unfair_lock (os\/lock.c) in all its strict glory. Stephan Tolksdorf: If you use it from Swift, you have to be careful, because it&rsquo;s a struct and Swift doesn&rsquo;t prevent [&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":"2023-01-27T19:54:44Z","apple_news_api_id":"39fe625c-679f-4d30-8fe4-62f491b8d0ba","apple_news_api_modified_at":"2023-01-27T19:54:44Z","apple_news_api_revision":"AAAAAAAAAAD\/\/\/\/\/\/\/\/\/\/w==","apple_news_api_share_url":"https:\/\/apple.news\/AOf5iXGefTTCP5GL0kbjQug","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":[800,880,31,1380,30,1381,54,138,71,901],"class_list":["post-15986","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-concurrency","tag-grand-central-dispatch-gcd","tag-ios","tag-ios-10","tag-mac","tag-macos-10-12","tag-objective-c","tag-optimization","tag-programming","tag-swift-programming-language"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/15986","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=15986"}],"version-history":[{"count":2,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/15986\/revisions"}],"predecessor-version":[{"id":38299,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/15986\/revisions\/38299"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=15986"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=15986"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=15986"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}