{"id":764,"date":"2023-10-28T08:59:21","date_gmt":"2023-10-28T08:59:21","guid":{"rendered":"https:\/\/baldsolutions.com\/?p=764"},"modified":"2023-10-28T09:55:46","modified_gmt":"2023-10-28T09:55:46","slug":"2-synchronization-primitives-in-net-barrier-class","status":"publish","type":"post","link":"https:\/\/baldsolutions.com\/index.php\/2023\/10\/28\/2-synchronization-primitives-in-net-barrier-class\/","title":{"rendered":"#2 Synchronization primitives in .NET &#8211; Barrier class"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<h1 class=\"wp-block-heading\">Introduction<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">This is a second post of the synchronization primitives series. In the previous <a href=\"https:\/\/baldsolutions.com\/index.php\/2023\/10\/07\/1-synchronization-primitives-in-net-interlocked-class\/\" target=\"_blank\" rel=\"noopener\" title=\"\">post<\/a> you can read about the <a href=\"https:\/\/learn.microsoft.com\/en-us\/dotnet\/api\/system.threading.interlocked?view=net-7.0\" target=\"_blank\" rel=\"noopener\" title=\"\">Interlocked <\/a>class primitive. In this post I describe and present an example regarding the <a href=\"https:\/\/learn.microsoft.com\/en-us\/dotnet\/api\/system.threading.barrier?view=net-7.0\" target=\"_blank\" rel=\"noopener\" title=\"\">Barrier<\/a> class &#8211; another interesting synchronization primitive that .NET offers.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">Barrier class<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">The Barrier class is an <a href=\"https:\/\/learn.microsoft.com\/en-us\/dotnet\/api\/system.idisposable?view=net-7.0\" target=\"_blank\" rel=\"noopener\" title=\"\">IDisposable<\/a> and non-static class that enables multiple tasks to cooperatively work on an algorithm in parallel through multiple phases (as in the definition in <a href=\"https:\/\/learn.microsoft.com\/en-us\/dotnet\/api\/system.threading.barrier?view=net-7.0#definition\" target=\"_blank\" rel=\"noopener\" title=\"\">docs<\/a>) .  Once you create a <a href=\"https:\/\/learn.microsoft.com\/en-us\/dotnet\/api\/system.threading.barrier?view=net-7.0\" target=\"_blank\" rel=\"noopener\" title=\"\">Barrier<\/a> class object you can access its all public and protected members (apart from the Dispose method) in a thread-safe manner (<a href=\"https:\/\/learn.microsoft.com\/en-us\/dotnet\/api\/system.threading.barrier?view=net-7.0#thread-safety\" target=\"_blank\" rel=\"noopener\" title=\"\">docs<\/a>). <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Usage scenario of the <a href=\"https:\/\/learn.microsoft.com\/en-us\/dotnet\/api\/system.threading.barrier?view=net-7.0\" target=\"_blank\" rel=\"noopener\" title=\"\">Barrier<\/a> class can look like this:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Create a <a href=\"https:\/\/learn.microsoft.com\/en-us\/dotnet\/api\/system.threading.barrier?view=net-7.0\" target=\"_blank\" rel=\"noopener\" title=\"\">Barrier<\/a> object by passing arguments to a constructor:\n<ul class=\"wp-block-list\">\n<li>participantCount &#8211; how many  threads participate in a phase.<\/li>\n\n\n\n<li>postPhaseAction (optional) &#8211; an action that is invoked  after each phase.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>Define an algorithm consisting of multiple phases. Ideally each phase should be executed in parallel by multiple threads. If a thread finishes its job in a phase it invokes one of the <a href=\"https:\/\/learn.microsoft.com\/en-us\/dotnet\/api\/system.threading.barrier?view=net-7.0#methods\" target=\"_blank\" rel=\"noopener\" title=\"\">SignalAndWait<\/a> overload &#8211; it means &#8220;The thread finished and waits for other threads to finish so that a phase can be finished&#8221;. Phase (N+1) can not be started if the Phase N is not finished.<\/li>\n\n\n\n<li>Define N threads and start the algorithm.<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">Let me show the real code example to ease the understanding of the steps.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">Example<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s define a problem to solve: &#8220;You are asked to find 7 Guids so that the two leading bytes of SHA256 of each Guid are zeros and store the Guids and hashes in a collection. Then find another 7 different Guids so that the three leading bytes of SHA256 of each Guid are zeros and store the Guids and hashes in another collection&#8221;.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">As you can see the probles consist of two phases:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Find 7 Guids so that hashes have two leading zeros,<\/li>\n\n\n\n<li>Find another 7 Guids so that hashes have three leading zeros.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Moreover, you can figure out that each phase can be processes by 7 independent threads. Each thread tries to find and store its own Guid and corresponding hash in the first phase and then in the second phase:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"793\" height=\"266\" src=\"https:\/\/baldsolutions.com\/wp-content\/uploads\/2023\/10\/image-19.png\" alt=\"\" class=\"wp-image-795\" srcset=\"https:\/\/baldsolutions.com\/wp-content\/uploads\/2023\/10\/image-19.png 793w, https:\/\/baldsolutions.com\/wp-content\/uploads\/2023\/10\/image-19-300x101.png 300w, https:\/\/baldsolutions.com\/wp-content\/uploads\/2023\/10\/image-19-768x258.png 768w\" sizes=\"auto, (max-width: 793px) 100vw, 793px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Once the problem is defined let&#8217;s jump to the code.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Create a <a href=\"https:\/\/learn.microsoft.com\/en-us\/dotnet\/api\/system.threading.barrier?view=net-7.0#definition\" target=\"_blank\" rel=\"noopener\" title=\"\">Barrier<\/a> object:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"727\" src=\"https:\/\/baldsolutions.com\/wp-content\/uploads\/2023\/10\/image-13-1024x727.png\" alt=\"\" class=\"wp-image-774\" srcset=\"https:\/\/baldsolutions.com\/wp-content\/uploads\/2023\/10\/image-13-1024x727.png 1024w, https:\/\/baldsolutions.com\/wp-content\/uploads\/2023\/10\/image-13-300x213.png 300w, https:\/\/baldsolutions.com\/wp-content\/uploads\/2023\/10\/image-13-768x545.png 768w, https:\/\/baldsolutions.com\/wp-content\/uploads\/2023\/10\/image-13.png 1103w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Define an algorithm consisting of multiple phases:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1018\" height=\"755\" src=\"https:\/\/baldsolutions.com\/wp-content\/uploads\/2023\/10\/image-14.png\" alt=\"\" class=\"wp-image-775\" srcset=\"https:\/\/baldsolutions.com\/wp-content\/uploads\/2023\/10\/image-14.png 1018w, https:\/\/baldsolutions.com\/wp-content\/uploads\/2023\/10\/image-14-300x222.png 300w, https:\/\/baldsolutions.com\/wp-content\/uploads\/2023\/10\/image-14-768x570.png 768w\" sizes=\"auto, (max-width: 1018px) 100vw, 1018px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Define N threads and start the algorithm:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"950\" height=\"600\" src=\"https:\/\/baldsolutions.com\/wp-content\/uploads\/2023\/10\/image-15.png\" alt=\"\" class=\"wp-image-776\" srcset=\"https:\/\/baldsolutions.com\/wp-content\/uploads\/2023\/10\/image-15.png 950w, https:\/\/baldsolutions.com\/wp-content\/uploads\/2023\/10\/image-15-300x189.png 300w, https:\/\/baldsolutions.com\/wp-content\/uploads\/2023\/10\/image-15-768x485.png 768w\" sizes=\"auto, (max-width: 950px) 100vw, 950px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">If you run the program you would see the following output (it might take ~1 minute to compute second collection of hashes so be patient):<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"840\" height=\"382\" src=\"https:\/\/baldsolutions.com\/wp-content\/uploads\/2023\/10\/image-16.png\" alt=\"\" class=\"wp-image-777\" srcset=\"https:\/\/baldsolutions.com\/wp-content\/uploads\/2023\/10\/image-16.png 840w, https:\/\/baldsolutions.com\/wp-content\/uploads\/2023\/10\/image-16-300x136.png 300w, https:\/\/baldsolutions.com\/wp-content\/uploads\/2023\/10\/image-16-768x349.png 768w\" sizes=\"auto, (max-width: 840px) 100vw, 840px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">As you can see the first phase (Phase0) started and computed all 7 hashes with two leading bytes equal zero (2 zero bytes equals &#8220;0000&#8221; in hex hence there is &#8220;0000&#8221; in Phase0 and &#8220;000000&#8221; in Phase1). Once the Phase0 is finished the Phase1 started and computed its own 7 hashes with three leading bytes equal zero. <\/p>\n\n\n\n<h1 class=\"wp-block-heading\">Summary<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">In this post I presented and explained the <a href=\"https:\/\/learn.microsoft.com\/en-us\/dotnet\/api\/system.threading.barrier?view=net-7.0#definition\" target=\"_blank\" rel=\"noopener\" title=\"\">Barrier<\/a> synchronization primitive in the .NET environment. The API of the <a href=\"https:\/\/learn.microsoft.com\/en-us\/dotnet\/api\/system.threading.barrier?view=net-7.0#definition\" target=\"_blank\" rel=\"noopener\" title=\"\">Barrier<\/a> class consists of members I did not mention in the post (see <a href=\"https:\/\/learn.microsoft.com\/en-us\/dotnet\/api\/system.threading.barrier?view=net-7.0#properties\" target=\"_blank\" rel=\"noopener\" title=\"\">Properties<\/a> and <a href=\"https:\/\/learn.microsoft.com\/en-us\/dotnet\/api\/system.threading.barrier?view=net-7.0#methods\" target=\"_blank\" rel=\"noopener\" title=\"\">Methods<\/a> sections) and I strongly encourage you to give it a try on your own. As always you can find source code on my <a href=\"https:\/\/github.com\/tglowka\/baldsolutions\/tree\/master\/dotnet\/synchronization-primitives\" target=\"_blank\" rel=\"noopener\" title=\"\">GitHub <\/a>repository.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Have a nice day, bye!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction This is a second post of the synchronization primitives series. In the previous post you can read about the Interlocked class primitive. In this&#8230;<\/p>\n<div class=\"more-link-wrapper\"><a class=\"more-link\" href=\"https:\/\/baldsolutions.com\/index.php\/2023\/10\/28\/2-synchronization-primitives-in-net-barrier-class\/\">Continue reading<span class=\"screen-reader-text\">#2 Synchronization primitives in .NET &#8211; Barrier class<\/span><\/a><\/div>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[2,16],"tags":[],"class_list":["post-764","post","type-post","status-publish","format-standard","hentry","category-net","category-synchronization-primitives","entry"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 4.9.9 - aioseo.com -->\n\t<meta name=\"description\" content=\"Introduction This is a second post of the synchronization primitives series. In the previous post you can read about the Interlocked class primitive. In this post I describe and present an example regarding the Barrier class - another interesting synchronization primitive that .NET offers. Barrier class The Barrier class is an IDisposable and non-static class\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Tomasz\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/baldsolutions.com\/index.php\/2023\/10\/28\/2-synchronization-primitives-in-net-barrier-class\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 4.9.9\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"Bald Solutions -\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"#2 Synchronization primitives in .NET \u2013 Barrier class - Bald Solutions\" \/>\n\t\t<meta property=\"og:description\" content=\"Introduction This is a second post of the synchronization primitives series. In the previous post you can read about the Interlocked class primitive. In this post I describe and present an example regarding the Barrier class - another interesting synchronization primitive that .NET offers. Barrier class The Barrier class is an IDisposable and non-static class\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/baldsolutions.com\/index.php\/2023\/10\/28\/2-synchronization-primitives-in-net-barrier-class\/\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2023-10-28T08:59:21+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2023-10-28T09:55:46+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:title\" content=\"#2 Synchronization primitives in .NET \u2013 Barrier class - Bald Solutions\" \/>\n\t\t<meta name=\"twitter:description\" content=\"Introduction This is a second post of the synchronization primitives series. In the previous post you can read about the Interlocked class primitive. In this post I describe and present an example regarding the Barrier class - another interesting synchronization primitive that .NET offers. Barrier class The Barrier class is an IDisposable and non-static class\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"BlogPosting\",\"@id\":\"https:\\\/\\\/baldsolutions.com\\\/index.php\\\/2023\\\/10\\\/28\\\/2-synchronization-primitives-in-net-barrier-class\\\/#blogposting\",\"name\":\"#2 Synchronization primitives in .NET \\u2013 Barrier class - Bald Solutions\",\"headline\":\"#2 Synchronization primitives in .NET &#8211; Barrier class\",\"author\":{\"@id\":\"https:\\\/\\\/baldsolutions.com\\\/index.php\\\/author\\\/tomasz3396\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/baldsolutions.com\\\/#organization\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/baldsolutions.com\\\/wp-content\\\/uploads\\\/2023\\\/10\\\/image-19.png\",\"@id\":\"https:\\\/\\\/baldsolutions.com\\\/index.php\\\/2023\\\/10\\\/28\\\/2-synchronization-primitives-in-net-barrier-class\\\/#articleImage\",\"width\":793,\"height\":266},\"datePublished\":\"2023-10-28T08:59:21+00:00\",\"dateModified\":\"2023-10-28T09:55:46+00:00\",\"inLanguage\":\"en-US\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/baldsolutions.com\\\/index.php\\\/2023\\\/10\\\/28\\\/2-synchronization-primitives-in-net-barrier-class\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/baldsolutions.com\\\/index.php\\\/2023\\\/10\\\/28\\\/2-synchronization-primitives-in-net-barrier-class\\\/#webpage\"},\"articleSection\":\".NET, Synchronization Primitives\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/baldsolutions.com\\\/index.php\\\/2023\\\/10\\\/28\\\/2-synchronization-primitives-in-net-barrier-class\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/baldsolutions.com#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/baldsolutions.com\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/baldsolutions.com\\\/index.php\\\/category\\\/net\\\/#listItem\",\"name\":\".NET\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/baldsolutions.com\\\/index.php\\\/category\\\/net\\\/#listItem\",\"position\":2,\"name\":\".NET\",\"item\":\"https:\\\/\\\/baldsolutions.com\\\/index.php\\\/category\\\/net\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/baldsolutions.com\\\/index.php\\\/2023\\\/10\\\/28\\\/2-synchronization-primitives-in-net-barrier-class\\\/#listItem\",\"name\":\"#2 Synchronization primitives in .NET &#8211; Barrier class\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/baldsolutions.com#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/baldsolutions.com\\\/index.php\\\/2023\\\/10\\\/28\\\/2-synchronization-primitives-in-net-barrier-class\\\/#listItem\",\"position\":3,\"name\":\"#2 Synchronization primitives in .NET &#8211; Barrier class\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/baldsolutions.com\\\/index.php\\\/category\\\/net\\\/#listItem\",\"name\":\".NET\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/baldsolutions.com\\\/#organization\",\"name\":\"Bald Solutions\",\"url\":\"https:\\\/\\\/baldsolutions.com\\\/\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/baldsolutions.com\\\/index.php\\\/author\\\/tomasz3396\\\/#author\",\"url\":\"https:\\\/\\\/baldsolutions.com\\\/index.php\\\/author\\\/tomasz3396\\\/\",\"name\":\"Tomasz\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/baldsolutions.com\\\/index.php\\\/2023\\\/10\\\/28\\\/2-synchronization-primitives-in-net-barrier-class\\\/#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d72f2f7f389921b820e5ef7c2880172fc2b9ae47698a933356df224581de0cc7?s=96&d=mm&r=g\",\"width\":96,\"height\":96,\"caption\":\"Tomasz\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/baldsolutions.com\\\/index.php\\\/2023\\\/10\\\/28\\\/2-synchronization-primitives-in-net-barrier-class\\\/#webpage\",\"url\":\"https:\\\/\\\/baldsolutions.com\\\/index.php\\\/2023\\\/10\\\/28\\\/2-synchronization-primitives-in-net-barrier-class\\\/\",\"name\":\"#2 Synchronization primitives in .NET \\u2013 Barrier class - Bald Solutions\",\"description\":\"Introduction This is a second post of the synchronization primitives series. In the previous post you can read about the Interlocked class primitive. In this post I describe and present an example regarding the Barrier class - another interesting synchronization primitive that .NET offers. Barrier class The Barrier class is an IDisposable and non-static class\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/baldsolutions.com\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/baldsolutions.com\\\/index.php\\\/2023\\\/10\\\/28\\\/2-synchronization-primitives-in-net-barrier-class\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/baldsolutions.com\\\/index.php\\\/author\\\/tomasz3396\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/baldsolutions.com\\\/index.php\\\/author\\\/tomasz3396\\\/#author\"},\"datePublished\":\"2023-10-28T08:59:21+00:00\",\"dateModified\":\"2023-10-28T09:55:46+00:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/baldsolutions.com\\\/#website\",\"url\":\"https:\\\/\\\/baldsolutions.com\\\/\",\"name\":\"Bald Solutions\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/baldsolutions.com\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"#2 Synchronization primitives in .NET \u2013 Barrier class - Bald Solutions","description":"Introduction This is a second post of the synchronization primitives series. In the previous post you can read about the Interlocked class primitive. In this post I describe and present an example regarding the Barrier class - another interesting synchronization primitive that .NET offers. Barrier class The Barrier class is an IDisposable and non-static class","canonical_url":"https:\/\/baldsolutions.com\/index.php\/2023\/10\/28\/2-synchronization-primitives-in-net-barrier-class\/","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"BlogPosting","@id":"https:\/\/baldsolutions.com\/index.php\/2023\/10\/28\/2-synchronization-primitives-in-net-barrier-class\/#blogposting","name":"#2 Synchronization primitives in .NET \u2013 Barrier class - Bald Solutions","headline":"#2 Synchronization primitives in .NET &#8211; Barrier class","author":{"@id":"https:\/\/baldsolutions.com\/index.php\/author\/tomasz3396\/#author"},"publisher":{"@id":"https:\/\/baldsolutions.com\/#organization"},"image":{"@type":"ImageObject","url":"https:\/\/baldsolutions.com\/wp-content\/uploads\/2023\/10\/image-19.png","@id":"https:\/\/baldsolutions.com\/index.php\/2023\/10\/28\/2-synchronization-primitives-in-net-barrier-class\/#articleImage","width":793,"height":266},"datePublished":"2023-10-28T08:59:21+00:00","dateModified":"2023-10-28T09:55:46+00:00","inLanguage":"en-US","mainEntityOfPage":{"@id":"https:\/\/baldsolutions.com\/index.php\/2023\/10\/28\/2-synchronization-primitives-in-net-barrier-class\/#webpage"},"isPartOf":{"@id":"https:\/\/baldsolutions.com\/index.php\/2023\/10\/28\/2-synchronization-primitives-in-net-barrier-class\/#webpage"},"articleSection":".NET, Synchronization Primitives"},{"@type":"BreadcrumbList","@id":"https:\/\/baldsolutions.com\/index.php\/2023\/10\/28\/2-synchronization-primitives-in-net-barrier-class\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/baldsolutions.com#listItem","position":1,"name":"Home","item":"https:\/\/baldsolutions.com","nextItem":{"@type":"ListItem","@id":"https:\/\/baldsolutions.com\/index.php\/category\/net\/#listItem","name":".NET"}},{"@type":"ListItem","@id":"https:\/\/baldsolutions.com\/index.php\/category\/net\/#listItem","position":2,"name":".NET","item":"https:\/\/baldsolutions.com\/index.php\/category\/net\/","nextItem":{"@type":"ListItem","@id":"https:\/\/baldsolutions.com\/index.php\/2023\/10\/28\/2-synchronization-primitives-in-net-barrier-class\/#listItem","name":"#2 Synchronization primitives in .NET &#8211; Barrier class"},"previousItem":{"@type":"ListItem","@id":"https:\/\/baldsolutions.com#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/baldsolutions.com\/index.php\/2023\/10\/28\/2-synchronization-primitives-in-net-barrier-class\/#listItem","position":3,"name":"#2 Synchronization primitives in .NET &#8211; Barrier class","previousItem":{"@type":"ListItem","@id":"https:\/\/baldsolutions.com\/index.php\/category\/net\/#listItem","name":".NET"}}]},{"@type":"Organization","@id":"https:\/\/baldsolutions.com\/#organization","name":"Bald Solutions","url":"https:\/\/baldsolutions.com\/"},{"@type":"Person","@id":"https:\/\/baldsolutions.com\/index.php\/author\/tomasz3396\/#author","url":"https:\/\/baldsolutions.com\/index.php\/author\/tomasz3396\/","name":"Tomasz","image":{"@type":"ImageObject","@id":"https:\/\/baldsolutions.com\/index.php\/2023\/10\/28\/2-synchronization-primitives-in-net-barrier-class\/#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/d72f2f7f389921b820e5ef7c2880172fc2b9ae47698a933356df224581de0cc7?s=96&d=mm&r=g","width":96,"height":96,"caption":"Tomasz"}},{"@type":"WebPage","@id":"https:\/\/baldsolutions.com\/index.php\/2023\/10\/28\/2-synchronization-primitives-in-net-barrier-class\/#webpage","url":"https:\/\/baldsolutions.com\/index.php\/2023\/10\/28\/2-synchronization-primitives-in-net-barrier-class\/","name":"#2 Synchronization primitives in .NET \u2013 Barrier class - Bald Solutions","description":"Introduction This is a second post of the synchronization primitives series. In the previous post you can read about the Interlocked class primitive. In this post I describe and present an example regarding the Barrier class - another interesting synchronization primitive that .NET offers. Barrier class The Barrier class is an IDisposable and non-static class","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/baldsolutions.com\/#website"},"breadcrumb":{"@id":"https:\/\/baldsolutions.com\/index.php\/2023\/10\/28\/2-synchronization-primitives-in-net-barrier-class\/#breadcrumblist"},"author":{"@id":"https:\/\/baldsolutions.com\/index.php\/author\/tomasz3396\/#author"},"creator":{"@id":"https:\/\/baldsolutions.com\/index.php\/author\/tomasz3396\/#author"},"datePublished":"2023-10-28T08:59:21+00:00","dateModified":"2023-10-28T09:55:46+00:00"},{"@type":"WebSite","@id":"https:\/\/baldsolutions.com\/#website","url":"https:\/\/baldsolutions.com\/","name":"Bald Solutions","inLanguage":"en-US","publisher":{"@id":"https:\/\/baldsolutions.com\/#organization"}}]},"og:locale":"en_US","og:site_name":"Bald Solutions -","og:type":"article","og:title":"#2 Synchronization primitives in .NET \u2013 Barrier class - Bald Solutions","og:description":"Introduction This is a second post of the synchronization primitives series. In the previous post you can read about the Interlocked class primitive. In this post I describe and present an example regarding the Barrier class - another interesting synchronization primitive that .NET offers. Barrier class The Barrier class is an IDisposable and non-static class","og:url":"https:\/\/baldsolutions.com\/index.php\/2023\/10\/28\/2-synchronization-primitives-in-net-barrier-class\/","article:published_time":"2023-10-28T08:59:21+00:00","article:modified_time":"2023-10-28T09:55:46+00:00","twitter:card":"summary","twitter:title":"#2 Synchronization primitives in .NET \u2013 Barrier class - Bald Solutions","twitter:description":"Introduction This is a second post of the synchronization primitives series. In the previous post you can read about the Interlocked class primitive. In this post I describe and present an example regarding the Barrier class - another interesting synchronization primitive that .NET offers. Barrier class The Barrier class is an IDisposable and non-static class"},"aioseo_meta_data":{"post_id":"764","title":null,"description":null,"keywords":[],"keyphrases":{"focus":{"keyphrase":"","score":0,"analysis":{"keyphraseInTitle":{"score":0,"maxScore":9,"error":1}}},"additional":[]},"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":"","og_custom_url":null,"og_article_section":null,"og_article_tags":[],"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"BlogPosting","isEnabled":true},"graphs":[]},"schema_type":"default","schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":"-1","robots_max_videopreview":"-1","robots_max_imagepreview":"large","priority":null,"frequency":"default","local_seo":null,"breadcrumb_settings":null,"limit_modified_date":false,"ai":null,"created":"2023-10-28 06:46:45","updated":"2025-06-04 05:28:42","seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/baldsolutions.com\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/baldsolutions.com\/index.php\/category\/net\/\" title=\".NET\">.NET<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t#2 Synchronization primitives in .NET \u2013 Barrier class\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/baldsolutions.com"},{"label":".NET","link":"https:\/\/baldsolutions.com\/index.php\/category\/net\/"},{"label":"#2 Synchronization primitives in .NET &#8211; Barrier class","link":"https:\/\/baldsolutions.com\/index.php\/2023\/10\/28\/2-synchronization-primitives-in-net-barrier-class\/"}],"_links":{"self":[{"href":"https:\/\/baldsolutions.com\/index.php\/wp-json\/wp\/v2\/posts\/764","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/baldsolutions.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/baldsolutions.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/baldsolutions.com\/index.php\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/baldsolutions.com\/index.php\/wp-json\/wp\/v2\/comments?post=764"}],"version-history":[{"count":28,"href":"https:\/\/baldsolutions.com\/index.php\/wp-json\/wp\/v2\/posts\/764\/revisions"}],"predecessor-version":[{"id":808,"href":"https:\/\/baldsolutions.com\/index.php\/wp-json\/wp\/v2\/posts\/764\/revisions\/808"}],"wp:attachment":[{"href":"https:\/\/baldsolutions.com\/index.php\/wp-json\/wp\/v2\/media?parent=764"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/baldsolutions.com\/index.php\/wp-json\/wp\/v2\/categories?post=764"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/baldsolutions.com\/index.php\/wp-json\/wp\/v2\/tags?post=764"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}