{"id":38065,"date":"2023-01-05T16:00:08","date_gmt":"2023-01-05T21:00:08","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=38065"},"modified":"2023-01-05T16:00:08","modified_gmt":"2023-01-05T21:00:08","slug":"limiting-swift-concurrencys-cooperative-pool","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2023\/01\/05\/limiting-swift-concurrencys-cooperative-pool\/","title":{"rendered":"Limiting Swift Concurrency&rsquo;s Cooperative Pool"},"content":{"rendered":"<p><a href=\"https:\/\/alejandromp.com\/blog\/limit-swift-concurrency-cooperative-pool\/\">Alejandro Martinez<\/a>:<\/p>\n<blockquote cite=\"https:\/\/alejandromp.com\/blog\/limit-swift-concurrency-cooperative-pool\/\"><p>In Swift Concurrency all your async code runs in a cooperative thread pool, unless you are using Actors (or in the future custom Executors, but that&rsquo;s a topic for another day). The beauty of the cooperative pool abstraction is that it allows us to not care about thread exhaustion, or even about our code running &ldquo;on the background&rdquo;, something I still see many developers get wrong.<\/p><p>[&#8230;]<\/p><p>In fact this cooperative pool is such a specific implementation detail that it could work totally different in other operative systems or more constrained enviornments.<\/p><p>[&#8230;]<\/p><p>And you can test how your code would behave in such a constrained system thanks to an environment variable that limits the cooperative pool.<\/p><p>Set <code>LIBDISPATCH_COOPERATIVE_POOL_STRICT=1<\/code> and see how the runtime will only create 1 thread on the pool.<\/p><\/blockquote>","protected":false},"excerpt":{"rendered":"<p>Alejandro Martinez: In Swift Concurrency all your async code runs in a cooperative thread pool, unless you are using Actors (or in the future custom Executors, but that&rsquo;s a topic for another day). The beauty of the cooperative pool abstraction is that it allows us to not care about thread exhaustion, or even about our [&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-05T21:00:11Z","apple_news_api_id":"6092940e-f9d4-400b-ab51-17debe814bc9","apple_news_api_modified_at":"2023-01-05T21:00:11Z","apple_news_api_revision":"AAAAAAAAAAD\/\/\/\/\/\/\/\/\/\/w==","apple_news_api_share_url":"https:\/\/apple.news\/AYJKUDvnUQAurURfevoFLyQ","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,56,31,2185,30,2223,71,2200,901],"class_list":["post-38065","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-concurrency","tag-debugging","tag-ios","tag-ios-16","tag-mac","tag-macos-13-ventura","tag-programming","tag-swift-concurrency","tag-swift-programming-language"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/38065","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=38065"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/38065\/revisions"}],"predecessor-version":[{"id":38066,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/38065\/revisions\/38066"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=38065"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=38065"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=38065"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}