<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>Multithreading on Georgy&#39;s Tech Blog</title>
    <link>https://georgy.dev/tags/multithreading/</link>
    <description>Recent content in Multithreading on Georgy&#39;s Tech Blog</description>
    <image>
      <title>Georgy&#39;s Tech Blog</title>
      <url>https://georgy.dev/images/cover.png</url>
      <link>https://georgy.dev/images/cover.png</link>
    </image>
    <generator>Hugo -- 0.146.7</generator>
    <language>en</language>
    <lastBuildDate>Wed, 21 Dec 2022 00:00:00 +0000</lastBuildDate>
    <atom:link href="https://georgy.dev/tags/multithreading/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>How to use mutex in Unreal Engine</title>
      <link>https://georgy.dev/posts/mutex/</link>
      <pubDate>Wed, 21 Dec 2022 00:00:00 +0000</pubDate>
      <guid>https://georgy.dev/posts/mutex/</guid>
      <description>&lt;p&gt;Unreal Engine has an alternative implementation of &lt;code&gt;std::mutex&lt;/code&gt; called &lt;code&gt;FCriticalSection&lt;/code&gt; which makes it possible for your data to be safely accessed from different threads, preventing race conditions. This takes the same approach, handling it with one thread locking until the other thread completes the necessary operations.&lt;/p&gt;
&lt;p&gt;There are two ways to handle lock/unlock logic.&lt;/p&gt;
&lt;p&gt;The first is low-level, which is used to directly lock and unlock threads. Use with caution due to possible &lt;a href=&#34;https://wiki.sei.cmu.edu/confluence/display/cplusplus/BB.&amp;#43;Definitions#BB.Definitions-deadlock&#34; target=&#34;_blank&#34;&gt;
    deadlocks
  &lt;/a&gt;. Just use &lt;code&gt;FCriticalSection::Lock&lt;/code&gt; and &lt;code&gt;FCriticalSection::Unlock&lt;/code&gt; functions where needed to follow this way.&lt;/p&gt;</description>
    </item>
    <item>
      <title>How to properly work with UObjects in background threads (GC)</title>
      <link>https://georgy.dev/posts/avoid-gc-async/</link>
      <pubDate>Wed, 30 Nov 2022 00:00:00 +0000</pubDate>
      <guid>https://georgy.dev/posts/avoid-gc-async/</guid>
      <description>&lt;p&gt;This article addresses the question of how to work with &lt;code&gt;UObjects&lt;/code&gt; in a thread-safe way when dealing with workers, async tasks, thread pools, or whatever else using a non-game thread.&lt;/p&gt;
&lt;p&gt;One critical issue to address is the handling of garbage collection. When passing an &lt;code&gt;UObject&lt;/code&gt;, which is not set to root, directly to a background thread, there&amp;rsquo;s a risk that the garbage collector may silently delete the passed &lt;code&gt;UObject&lt;/code&gt;. Even frequent validity checks of the &lt;code&gt;UObject&lt;/code&gt; (e.g. &lt;code&gt;IsValidLowLevel()&lt;/code&gt;) on a background thread cannot guarantee the object&amp;rsquo;s survival even moments after the check.&lt;/p&gt;</description>
    </item>
    <item>
      <title>How to use async task in Unreal Engine</title>
      <link>https://georgy.dev/posts/async-task/</link>
      <pubDate>Sun, 31 Jul 2022 00:00:00 +0000</pubDate>
      <guid>https://georgy.dev/posts/async-task/</guid>
      <description>&lt;p&gt;Unreal Engine has a useful feature called &lt;code&gt;AsyncTask&lt;/code&gt; that allows you to execute code asynchronously via Task Graph system. It functions by running specific code on a specified thread and is primarily used when the task is too heavy to be executed instantly without blocking the game thread.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-cpp&#34; data-lang=&#34;cpp&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;AsyncTask&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;ENamedThreads&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;::&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;AnyThread&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;[]()&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;	&lt;span class=&#34;c1&#34;&gt;// This code will run asynchronously, without freezing the game thread
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;});&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;You can also create nested calls to asynchronous tasks, for example:&lt;/p&gt;</description>
    </item>
    <item>
      <title>How to create a multi-threaded for loop in Unreal Engine</title>
      <link>https://georgy.dev/posts/parallel-for-loop/</link>
      <pubDate>Sat, 23 Jul 2022 00:00:00 +0000</pubDate>
      <guid>https://georgy.dev/posts/parallel-for-loop/</guid>
      <description>&lt;p&gt;Unreal Engine has different approaches to parallelize your code and one of them is &lt;code&gt;ParallelFor&lt;/code&gt;. It is used when it is necessary to execute code multiple times with different number-based inputs, basically what a regular for loop does. But unlike a regular for loop that executes sequentially, &lt;code&gt;ParallelFor&lt;/code&gt; runs on different threads, with possible different order of execution.&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s say our task is to simply sum the values from the &lt;code&gt;TArray&amp;lt;int32&amp;gt;&lt;/code&gt; array. It&amp;rsquo;s easiest to do this:&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
