{"id":1265,"date":"2016-10-31T17:40:32","date_gmt":"2016-10-31T17:40:32","guid":{"rendered":"http:\/\/ninecrows.com\/career\/?p=1265"},"modified":"2016-10-31T17:40:32","modified_gmt":"2016-10-31T17:40:32","slug":"i-just-realized-that-in-a-gcol-environment-lazy-creation-may-not-always-need-locks","status":"publish","type":"post","link":"https:\/\/ninecrows.com\/career\/2016\/10\/31\/i-just-realized-that-in-a-gcol-environment-lazy-creation-may-not-always-need-locks\/","title":{"rendered":"I just realized that in a gcol environment, lazy creation may not always need locks&#8230;"},"content":{"rendered":"<p>&#8230;where you&#8217;re doing lazy construction of something that is an immutable singleton. If creating more than one isn&#8217;t an issue (and since the object created is fixed it shouldn&#8217;t generally be) then the creation \/initialization race isn&#8217;t relevant.<\/p>\n<p>The garbage collector will clean up any duplicates that get made. The callers will have valid objects until they&#8217;re done. Whichever object gets stored last will become the object that is served to all subsequent customers.<\/p>\n<p>This avoids the costs of locking a mutex (or something similar) and should result in simpler code. Once you have established the static reference, all subsequent requests just get that object.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8230;where you&#8217;re doing lazy construction of something that is an immutable singleton. If creating more than one isn&#8217;t an issue (and since the object created is fixed it shouldn&#8217;t generally be) then the creation \/initialization race isn&#8217;t relevant. The garbage collector will clean up any duplicates that get made. The callers will have valid objects &hellip; <a href=\"https:\/\/ninecrows.com\/career\/2016\/10\/31\/i-just-realized-that-in-a-gcol-environment-lazy-creation-may-not-always-need-locks\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">I just realized that in a gcol environment, lazy creation may not always need locks&#8230;<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[1],"tags":[],"class_list":["post-1265","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p7F2Qc-kp","jetpack-related-posts":[],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/ninecrows.com\/career\/wp-json\/wp\/v2\/posts\/1265"}],"collection":[{"href":"https:\/\/ninecrows.com\/career\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ninecrows.com\/career\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ninecrows.com\/career\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ninecrows.com\/career\/wp-json\/wp\/v2\/comments?post=1265"}],"version-history":[{"count":1,"href":"https:\/\/ninecrows.com\/career\/wp-json\/wp\/v2\/posts\/1265\/revisions"}],"predecessor-version":[{"id":1266,"href":"https:\/\/ninecrows.com\/career\/wp-json\/wp\/v2\/posts\/1265\/revisions\/1266"}],"wp:attachment":[{"href":"https:\/\/ninecrows.com\/career\/wp-json\/wp\/v2\/media?parent=1265"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ninecrows.com\/career\/wp-json\/wp\/v2\/categories?post=1265"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ninecrows.com\/career\/wp-json\/wp\/v2\/tags?post=1265"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}