<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Fatih Öztemir on Medium]]></title>
        <description><![CDATA[Stories by Fatih Öztemir on Medium]]></description>
        <link>https://medium.com/@fatihoztemir66?source=rss-ea51060a07c2------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*I6KCNdDTLSvX__UZS5FnWA.jpeg</url>
            <title>Stories by Fatih Öztemir on Medium</title>
            <link>https://medium.com/@fatihoztemir66?source=rss-ea51060a07c2------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 01:08:59 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@fatihoztemir66/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[What is the Concurrency?]]></title>
            <link>https://medium.com/@fatihoztemir66/what-is-the-concurrency-ab381a0e11cf?source=rss-ea51060a07c2------2</link>
            <guid isPermaLink="false">https://medium.com/p/ab381a0e11cf</guid>
            <category><![CDATA[dotnet-core]]></category>
            <category><![CDATA[parallel-programming]]></category>
            <category><![CDATA[asyncawait]]></category>
            <category><![CDATA[concurrency]]></category>
            <category><![CDATA[parallelism]]></category>
            <dc:creator><![CDATA[Fatih Öztemir]]></dc:creator>
            <pubDate>Tue, 18 Oct 2022 19:59:00 GMT</pubDate>
            <atom:updated>2022-10-18T19:59:00.012Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*710vh7SK17_7OXuG084u0g.png" /></figure><p>One of the first issues that come to mind when it comes to producing quality software products is concurrency. Concurrency has many sub-titles such as asynchronous programming, reactive programming, parallel programming. We will talk about asynchronous and parallel programming, which are the most used concurrency types in the software world.</p><p>Concurrency can be defined as the ability of a system to do more than one job at the same time. If we consider the server architecture, this system meets many requests at the same time. But have you thought about how the system will react to other requests that keep coming, with a response time of 30 seconds since the first request is a heavy operation? If concurrency is not used, the user is suspended until the first request is completed. At the end of 30 seconds, after the user receives a response to his first request, he starts getting answers for his other requests. This is a pretty bad scenario for user experience. Considering the human capacity and the number of active users in the applications in today’s world, this is not an experience we want at all. Concurrency should be used to respond to more than one request at the same time.</p><p>There are two operations where Concurrency is used. These are I/O-bound and CPU-bound operations. I/O-bound operations “Will it wait for a data to come from the database or remote server?” can be distinguished by the question. If the answer is “yes”, this operation is an I/O-bound operation and asynchronous programming is generally preferred in these operations. If a difficult and costly operation is to be performed, it is a CPU-bound operation and parallel programming is preferred for these operations.</p><h4>Asynchronous Programming</h4><p>First, let’s examine the concepts of process and thread.</p><p><strong>Process</strong> is a running application.<br><strong>Thread</strong> is a small part of the process that does work.</p><p>Asynchronous programming is a form of concurrency that <strong>keeps the use of threads to a minimum</strong>. The reason why the number of threads is wanted to be kept to a minimum is that the cost of creating a thread in C # language is very high. The size of each thread in C# is 1MB by default. The keywords that keep the number of threads to a minimum are async/await words. The type of an operation defined as Async is Task. A task defined as a task is guaranteed to be completed in the future.</p><h4>async/await</h4><p>Asynchronous programming is available in many languages and there are differences in its use. In this article, we will examine how to make a function asynchronous in C#.</p><p>First of all, async/await keywords are preferred for I/O-bound operations. The function that will run asynchronously is marked with the <strong>async</strong> keyword. Then the <strong>await</strong> keyword should be added to the beginning of the line of the function that will run asynchronously. In order for the word await to be used, the line in which it is found must return a value of type <strong>Task </strong>or<strong> Task&lt;T&gt;</strong>. The await word actually waits for that process to complete. During this waiting period, the thread used for the function is sent to the thread pool and the thread stays waiting to respond other requests. When the operation on the awaited line is completed, the function continues by requesting a random thread from the thread pool.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/59b2da5ce743b7de5d974648df5f3809/href">https://medium.com/media/59b2da5ce743b7de5d974648df5f3809/href</a></iframe><h4>Task.FromResult()</h4><p>Task.FromResult() allows any value to be wrapped with a Task. For example, this structure should be used when a function that is required to work synchronously has to be run asynchronously. This situation occurs when the interface used does not have a synchronous method but an asynchronous method.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1c293be837f760117af4b06c96d0fe2d/href">https://medium.com/media/1c293be837f760117af4b06c96d0fe2d/href</a></iframe><p>In the example above, the FeedAsync method of the interface expects a return value of type Task&lt;Human&gt;. Since the method we wrote proceeds synchronously, there is no need to return a Task. Therefore, it returns the return value of synchronous methods as Task with Task.FromResult().</p><h4>Task.Run()</h4><p>The Task.Run() method is generally used for CPU-bound operations. This method takes action as a parameter. This action taken as a parameter runs in a separate thread. Task.Run() is a costly operation because it uses a separate thread. Unnecessary usage should only be used for necessary processes as it will consume resources (memory, cpu etc.) in the system.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fa5a848d358fdb10e31e9e7b29ea621b/href">https://medium.com/media/fa5a848d358fdb10e31e9e7b29ea621b/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/382/1*dYG1jBuxTYl2UqhOmVk-jg.png" /></figure><p>When the above piece of code is run, it is seen that the Task.Run() method is executed in a different thread than the main thread.</p><h4>Task.WhenAll()</h4><p>The Task.WhenAll() method is used for more than one asynchronous operation. It takes an array holding data of type Task as a parameter.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8a0044d54da9b2ae4e205e0e1d9a73af/href">https://medium.com/media/8a0044d54da9b2ae4e205e0e1d9a73af/href</a></iframe><h4>Parallel Programming</h4><p>Parallel Programming is a method used to execute a process in more than one thread at the same time. Generally, CPU-bound processes are used. Implementing parallel programming in C# is quite easy. The code can be run in parallel with Parallel.For, Parallel.ForEach and AsParallel() method used in LINQ.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d5aa2af101067f7efbb14ac520b63316/href">https://medium.com/media/d5aa2af101067f7efbb14ac520b63316/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/450/1*fFayVBRT0LXVfO3G6dhR0Q.png" /></figure><p>If we print the numbers of the threads that perform the operations in parallel.ForEach in the above snippet, it will be seen that the threads that perform these operations are different threads. This indicates that more than one thread is running at the same time.</p><p>Parallel programming generally uses the processor for operations that will keep it busy. The use of parallel programming shortens the response time of requests. Of course, parallel programming is very risky to use because it consumes a lot of resources. It should be noted that the process used is an intensive process that is really worth it.</p><p>In this article, I tried explain Concurrency. See you in other articles…</p><p>REFERENCES</p><p>1-) <a href="https://learning.oreilly.com/library/view/concurrency-in-c/9781492054498/">https://learning.oreilly.com/library/view/concurrency-in-c/9781492054498/</a><br>2-) <a href="https://docs.microsoft.com/en-us/dotnet/csharp/async#recognize-cpu-bound-and-io-bound-work">https://docs.microsoft.com/en-us/dotnet/csharp/async#recognize-cpu-bound-and-io-bound-work</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ab381a0e11cf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[C# ile Concurrency]]></title>
            <link>https://medium.com/@fatihoztemir66/c-ile-concurrency-fb29e9b9070?source=rss-ea51060a07c2------2</link>
            <guid isPermaLink="false">https://medium.com/p/fb29e9b9070</guid>
            <category><![CDATA[asenkron-programlama]]></category>
            <category><![CDATA[concurrency]]></category>
            <category><![CDATA[c-sharp-programming]]></category>
            <category><![CDATA[paralel-programlama]]></category>
            <category><![CDATA[net-core]]></category>
            <dc:creator><![CDATA[Fatih Öztemir]]></dc:creator>
            <pubDate>Mon, 03 Oct 2022 18:03:56 GMT</pubDate>
            <atom:updated>2022-10-03T18:03:56.568Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EkH3tZDoY3pMT5CDL0tPJg.png" /></figure><h3>Concurrency Nedir?</h3><p>Kaliteli yazılım ürünleri ortaya konulmak istenildiğinde akla ilk gelen konulardan biri de eşzamanlılık yani concurrency’dir. Concurrency’nin asenkron programlama, reactive programlama, paralel programlama gibi birçok alt başlığı vardır. Yazılım dünyasında en çok kullanılan concurrency çeşitleri olan asenkron ve paralel programlama konularına değineceğiz.</p><p>Concurrency, en kısa haliyle bir sistemin aynı anda birden fazla iş yapabilmesi olarak tanımlanabilir. Sunucu mimarisini ele alacak olursak, bu sistem aynı anda pek çok isteği karşılamaktadır. Peki ya sistemin, ilk isteğin ağır bir işlem olması nedeniyle 30 saniyeyi bulacak olan cevap süresiyle gelmeye devam eden diğer istekler karşısında nasıl reaksiyon alacağını düşün müydünüz? Eğer concurrency kullanılmamışsa ilk isteğin işlemi tamamlanana kadar kullanıcı bekletilir. 30 saniye sonunda kullanıcı ilk isteğine karşılık aldıktan sonra diğer istekleri için karşılık almaya başlar. Bu tahmin edileceği üzere kullanıcı deneyimi açısından oldukça kötü bir senaryodur. Günümüz dünyasındaki insan kapasitesini ve uygulamalardaki aktif kullanıcı sayısını düşündüğümüzde bu hiç de bizim istediğimiz bir deneyim değildir. Aynı anda gelen birden fazla isteğe cevap verebilmek için concurrency kullanılmalıdır.</p><p>Concurrency’nin kullanıldığı iki operasyon vardır. Bunlar <strong>I/O-bound</strong> ve <strong>CPU-bound </strong>işlemleridir. I/O-bound işlemleri “Veritabanından veya sunucudan bir verinin gelmesi beklenecek mi?” sorusuyla ayırt edilebilir. Cevap “<strong>evet</strong>” ise bu işlem bir <strong>I/O-bound</strong> işlemidir ve bu işlemlerde genel olarak <strong>asenkron</strong> programlama tercih edilir. Eğer <strong>zorlu</strong> ve <strong>maliyeti yüksek</strong> bir işlem yapılacaksa da bu <strong>CPU-bound</strong> işlemidir ve bu işlemlerde <strong>paralel</strong> programlama tercih edilir.</p><h4>Asenkron Programlama</h4><p>Öncelikle process ve thread kavramlarını inceleyelim.</p><p><strong>Process, </strong>çalışan bir uygulamadır.<br><strong>Thread </strong>ise<strong> </strong>process’in iş yapan küçük bir parçasıdır.</p><p>Asenkron programlama<strong> thread kullanımının en az sayıda tutulmasını</strong> sağlayan bir concurrency biçimidir. Thread sayısının en az miktarda tutulmak istenmesinin sebebi ise C# dilinde bir thread oluşturmanın maliyetinin çok yüksek olmasıdır. C#’ta her bir threadin boyutu varsayılan olarak 1MB’tır. Thread sayısının minimumda tutulmasını sağlayan anahtar kelimeler ise<strong> async/await </strong>kelimeleridir. Async olarak tanımlanan bir işlemin türü <strong>Task</strong>’tır. Task olarak tanımlanan bir işlemin gelecekte tamamlanacağı garanti edilmiştir.</p><h4>async/await Kullanımı</h4><p>Asenkron programlama, bir çok dilde yer almaktadır ve her dildeki kullanımında farklılıklar yer almaktadır. Bu yazıda C# ile bir fonksiyon nasıl asenkron yapılır incelenecektir.</p><p>Öncelikle <strong>async/await </strong>anahtar kelimeleri <strong>I/O-bound</strong> işlemlerinde tercih edilir. Asenkron çalışacak olan fonksiyon async anahtar kelimesiyle işaretlenir. Ardından fonksiyonun asenkron çalışacak olan satırının başına await anahtar kelimesi eklenmelidir. Await kelimesinin kullanılabilmesi için bulunduğu satırın <strong>Task</strong> veya <strong>Task&lt;T&gt; </strong>tipinde bir veri döndürmesi gerekmektedir. <strong>Await</strong> kelimesi aslında o işlemin tamamlanmasını beklemeyi sağlar. Bu bekleme sürecinde fonksiyon için kullanılan <strong>thread</strong>, <strong>thread pool</strong>’a yollanır ve thread diğer requestleri karşılamak üzere beklemede kalır. Await edilen satırdaki işlem tamamlandığında ise fonksiyon thread pool’dan rastgele bir thread isteyerek işleme devam eder.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/59b2da5ce743b7de5d974648df5f3809/href">https://medium.com/media/59b2da5ce743b7de5d974648df5f3809/href</a></iframe><h4>Task.FromResult() kullanımı</h4><p>Task.FromResult() herhangi bir değerin Task ile sarmalanmasını sağlar. Örneğin senkron çalışması istenilen bir fonksiyonu asenkron çalıştırmak zorunda kalındığında bu yapı kullanılmalıdır. Bu durum, kullanılan interface’in senkron methodu olmayıp asenkron methodu olduğunda karşımıza çıkar.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1c293be837f760117af4b06c96d0fe2d/href">https://medium.com/media/1c293be837f760117af4b06c96d0fe2d/href</a></iframe><p>Yukarıdaki örnekte interface’in FeedAsync methodu <strong>Task&lt;Human&gt;</strong> tipinde bir geri dönüş değeri beklemektedir. Yazdığımız method senkron bir şekilde ilerlediği için Task dönülmesine ihtiyaç yoktur. Bundan dolayı senkron methodlardaki geri dönüş değerini <strong>Task.FromResult()</strong> ile Task olarak döndürmektedir.</p><h4>Task.Run() Kullanımı</h4><p>Task.Run() methodu genel olarak CPU’ya bağlı işlemlerde kullanılır. Bu method parametre olarak action almaktadır. Parametre olarak alınan bu action ayrı bir thread’de çalışmaktadır. Task.Run() ayrı bir thread kullandığından dolayı maliyetli bir işlemdir. Gereksiz kullanım sistemdeki kaynakları (memory, cpu etc.) fazla tüketeceğinden sadece gerekli işlemlerde kullanılmalıdır.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fa5a848d358fdb10e31e9e7b29ea621b/href">https://medium.com/media/fa5a848d358fdb10e31e9e7b29ea621b/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/382/1*QT9vFJjqS6hbZgakPtCgXA.png" /></figure><p>Yukarıdaki kod parçası çalıştırıldığında Task.Run() methodunun main threadden farklı bir threadde gerçekleştiği görülür.</p><h4>Task.WhenAll() Kullanımı</h4><p>Task.WhenAll() methodu birden fazla asenkron işlem için kullanılan methoddur. Parametre olarak Task tipinde veri tutan bir dizi almaktadır.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8a0044d54da9b2ae4e205e0e1d9a73af/href">https://medium.com/media/8a0044d54da9b2ae4e205e0e1d9a73af/href</a></iframe><h3>Paralel Programlama</h3><p>Paralel Programlama bir işlemi aynı anda birden fazla threadde yürütmek için kullanılan bir yöntemdir. Genel olarak CPU-bound işlemler kullanılmaktadır. C#’ta paralel programlamayı uygulamak oldukça kolaydır. <strong>Parallel.For</strong>, <strong>Parallel.ForEach</strong> ve LINQ’da kullanılan <strong>AsParallel()</strong> methoduyla kod paralel olarak çalıştırılabilir.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d5aa2af101067f7efbb14ac520b63316/href">https://medium.com/media/d5aa2af101067f7efbb14ac520b63316/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/450/1*W1aRVujzdELTIadQdj17KA.png" /></figure><p>Yukarıdaki kod parçasında parallel.ForEach içinde işlemleri yapan threadlerin numaralarını yazdırırsak bu işlemleri yapan threadlerin farklı threadler olduğu görülür. Bu da aynı anda birden fazla threadin çalıştığını gösterir.</p><p>Paralel programlama genel olarak işlemciyi yoğun bir şekilde meşgul edecek işlemlerde kullanır. Paralel programlama kullanımı isteklerin cevap süresini kısaltır. Tabii ki parallel programlama çok fazla kaynak tükettiğinden dolayı kullanılması bir hayli risklidir. Kullanılan işlemin gerçekten buna değecek kadar yoğun bir işlem olmasına dikkat edilmelidir.</p><p>Bu yazıda asenkron programlamaya kısaca değinmeye çalıştım. Başka yazılarda görüşmek üzere…</p><p>KAYNAKÇA</p><p><a href="https://learning.oreilly.com/library/view/concurrency-in-c/9781492054498/">1-) https://learning.oreilly.com/library/view/concurrency-in-c/9781492054498/</a><br>2-)<a href="https://docs.microsoft.com/en-us/dotnet/csharp/async#recognize-cpu-bound-and-io-bound-work">https://docs.microsoft.com/en-us/dotnet/csharp/async#recognize-cpu-bound-and-io-bound-work</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fb29e9b9070" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>