<?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 Pointdexter on Medium]]></title>
        <description><![CDATA[Stories by Pointdexter on Medium]]></description>
        <link>https://medium.com/@manikurmi14?source=rss-962ed77796aa------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*aqn-0CJreuSZC3MAr2vg5Q.jpeg</url>
            <title>Stories by Pointdexter on Medium</title>
            <link>https://medium.com/@manikurmi14?source=rss-962ed77796aa------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 27 Nov 2026 19:15:06 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@manikurmi14/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[Goroutines, Channels, and the Fine Art of Not Shooting Yourself in the Foot]]></title>
            <link>https://medium.com/@manikurmi14/goroutines-channels-and-the-fine-art-of-not-shooting-yourself-in-the-foot-ea825cddc075?source=rss-962ed77796aa------2</link>
            <guid isPermaLink="false">https://medium.com/p/ea825cddc075</guid>
            <category><![CDATA[goroutines]]></category>
            <category><![CDATA[go]]></category>
            <category><![CDATA[channel]]></category>
            <dc:creator><![CDATA[Pointdexter]]></dc:creator>
            <pubDate>Sat, 31 Oct 2026 09:25:48 GMT</pubDate>
            <atom:updated>2026-10-31T09:25:48.210Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jpK8sekpKl9_O4_acMft_Q.jpeg" /></figure><p><em>Note: This article assumes you already know the basics of Go syntax and have written a few Go programs. If you’ve recently completed a Go tutorial but still find goroutines and channels confusing, this article is for you.</em></p><p><em>We’ll explore concurrency through practical examples, analogies, and some of the mistakes you’re likely to make along the way. Hopefully, by the end, things will start to click.</em></p><h3>Chapter 1: In the Beginning!</h3><pre>package main<br><br>import (<br> &quot;fmt&quot;<br> &quot;time&quot;<br>)<br><br>func brewCoffee() {<br> fmt.Println(&quot;Brewing coffee...&quot;)<br> time.Sleep(2 * time.Second)<br> fmt.Println(&quot;Coffee is ready!&quot;)<br>}<br><br>func main() {<br> go brewCoffee()<br> fmt.Println(&quot;Meanwhile, checking emails...&quot;)<br> time.Sleep(3 * time.Second)<br>}</pre><p>You slap the word go in front of a function call, and suddenly it’s running concurrently. No thread pools to configure. No Runnable interfaces to implement. Just… go. It’s almost rude how easy it is.</p><p>This is a goroutine: a lightweight thread managed by the Go runtime, not the OS. They start at about 2KB of stack space (compare that to a typical OS thread’s 1–8MB) and grow as needed. You can spin up hundreds of thousands of them on a laptop without your fans sounding like a jet engine. Try that with Thread objects in most other languages and your OS will politely — or not so politely — tell you to stop.</p><p>Though, is right there in the example above. If you remove that time.Sleep(3 * time.Second) at the end of main, your program exits before the coffee ever brews. Why?</p><p>Goroutines don’t keep the program alive. main(), because this guy is the boss, and when the boss goes home, everyone goes home — mid-sentence, mid-brew, mid-anything. This is why your first goroutine program often prints nothing at all.</p><h3>Chapter 2: Channels — “Please Just Talk to Each Other”</h3><pre>func main() {<br> messages := make(chan string)<br><br> go func() {<br>  messages &lt;- &quot;Order #42: one large pizza &quot;<br> }()<br><br> msg := &lt;-messages<br> fmt.Println(msg)<br>}</pre><p>Think of a channel like a tube that lets goroutines pass messages to each other. One goroutine <strong>sends</strong> a message using messages &lt;-, and another goroutine <strong>receives</strong> it using &lt;-messages.</p><p>However, with an <strong>unbuffered channel</strong>, the sender has to wait until another goroutine is ready to receive the message. So both sides need to meet at the same time.</p><p>You must be think where’s that unbuffered channel came from. you may also expecting, what is buffered channel then.</p><p>A <strong>buffered channel</strong> is a channel that can hold a certain number of values <strong>without requiring another goroutine to receive them immediately</strong></p><pre>package main<br><br>import &quot;fmt&quot;<br><br>func main() {<br>    ch := make(chan string, 2) // A buffered channel has limited room<br>// The 2 means the channel can store 2 values<br>//All two can be sent without a receiver immediately receiving them<br><br>    ch &lt;- &quot;Hello&quot;<br>    ch &lt;- &quot;World&quot;<br><br>    fmt.Println(&lt;-ch)<br>    fmt.Println(&lt;-ch)<br>}<br><br>//output:<br>// Hello<br>// World</pre><p>Notice something important: <strong>we sent both values before receiving either one</strong></p><h3>Chapter 3: Deadlock</h3><p><em>Every Go developer eventually writes something like this:</em></p><pre>func main() {<br> ch := make(chan int)<br> ch &lt;- 42 // sending, but nobody&#39;s receiving<br> fmt.Println(&lt;-ch)<br>}</pre><p><em>And gets rewarded with:</em></p><pre>fatal error: all goroutines are asleep - deadlock!</pre><p>This is Go’s way of saying: “You sent a message into a tube with nobody on the other end, and then you also left, so now the tube is just sitting there. Forever. I’m not mad, just disappointed.”<br>The beautiful thing is that Go’s runtime actually detects this and crashes loudly instead of hanging silently forever, which is more mercy than a lot of languages show you. Some concurrency bugs in other languages will let your program just… sit there, spinning its wheels, while you frantically waiting.</p><p>btw this only happens in <strong>unbuffered channel, </strong>however in buffered channel:</p><pre>ch := make(chan int, 1) // buffer of 1<br>ch &lt;- 42                // doesn&#39;t block! there&#39;s room in the tube<br>fmt.Println(&lt;-ch)</pre><p><em>Now the channel can hold one value without anyone standing by to catch it immediately. Take it like as a voicemail /message— you can leave the message and walk away.</em></p><h3>Chapter 4: The Race Condition, or “Two Goroutines Enter, One Number Leaves (Wrong)”</h3><p><em>here I’m expecting that you know what is a race condition and Waitgroup in in Go, if you don’t just go and read about them. Anyway I’m adding a short not for understanding if You don’t know!</em></p><h3>What is a Race Condition?</h3><p>Race condition happens when:</p><ul><li>Two or more goroutines <strong>access</strong> the same variable<strong> at the same time</strong>…</li><li>AND at least one of them is trying to write/change it.</li></ul><p>This causes unpredictable results!</p><h3>WaitGroup</h3><p>When you launch a goroutine with go someFunction(), your program doesn&#39;t wait for it to finish.<br>If main() exits, all goroutines are killed.<br>WaitGroup helps us <strong>wait</strong> for all goroutines to finish before moving on.</p><pre>func main() {<br> counter := 0<br> var wg sync.WaitGroup<br><br> for i := 0; i &lt; 1000; i++ {<br>  wg.Add(1)<br>  go func() {<br>   defer wg.Done() //instead of using sleep(mention in the above) and we use defer and waitgroup<br>// like this -&gt; time.Sleep(3 * time.Second)<br><br>   counter++ // uh oh<br>  }()<br> }<br><br> wg.Wait()<br> fmt.Println(&quot;Final count:&quot;, counter)<br>}</pre><p>You’d expect 1000. You might get 1000. You might also get 973, or 988, or some other number that makes you question your understanding of arithmetic. This is a race condition: multiple goroutines reading and writing counter at the same time, stepping on each other’s toes like it’s a crowded elevator.<br>Go even ships a built-in tattletale for this. Run your program with:</p><pre>go run -race main.go</pre><p>And it will point at the exact line where two goroutines are squabbling over the same variable, complete with stack traces, like a substitute teacher who saw F ing around.<br>The fix is either a mutex (a literal lock — one goroutine holds the key, does its business, hands the key back):</p><pre>var mu sync.Mutex<br>mu.Lock()<br>counter++<br>mu.Unlock()</pre><p>…or, more idiomatically in Go, funnel the increments through a channel so only one goroutine ever owns counter. Because remember: share memory by communicating, not the other way around.</p><h3>Chapter 5: select — Go’s Concurrency</h3><p>If channels are pneumatic tubes, select is the person standing in front of five of them at once, ready to grab whichever one spits something out first:</p><pre>func main() {<br> c1 := make(chan string)<br> c2 := make(chan string)<br><br> go func() {<br>  time.Sleep(1 * time.Second)<br>  c1 &lt;- &quot;Result from server A&quot;<br> }()<br> go func() {<br>  time.Sleep(2 * time.Second)<br>  c2 &lt;- &quot;Result from server B&quot;<br> }()<br><br> select {<br> case msg1 := &lt;-c1:<br>  fmt.Println(msg1)<br> case msg2 := &lt;-c2:<br>  fmt.Println(msg2)<br> }<br>}</pre><p>This is basically Go’s version of “whichever pizza place calls back first, we’re ordering from them.” It’s how you implement timeouts, cancellation, and fan-in patterns without writing a single callback pyramid of doom. Add a time.After() case and you’ve got a timeout in about three lines:</p><pre>select {<br>case res := &lt;-c1:<br> fmt.Println(res)<br>case &lt;-time.After(3 * time.Second):<br> fmt.Println(&quot;Nobody answered in time. Rude.&quot;)<br>}</pre><h3><strong>Chapter 6: The Goroutine Leak</strong></h3><p>This one’s sneaky because your program doesn’t crash. It just… quietly accumulates goroutines like a hoarder accumulates cardboard boxes, until your memory usage climbs and nobody knows why.</p><pre>func leaky() {<br> ch := make(chan int)<br> go func() {<br>  val := &lt;-ch // waits here forever if nobody ever sends<br>  fmt.Println(val)<br> }()<br> // function returns, ch is forgotten, goroutine waits eternally<br>}</pre><p>Every time leaky() is called, it abandons a goroutine that will sit there, blocked, waiting for a message that will never come —. Multiply this by ten thousand requests per hour and you have a very confusing production incident.<br>The fix is almost always context.Context, Go’s standard way of saying “and also, please stop if I tell you to”:</p><pre>func notLeaky(ctx context.Context) {<br> ch := make(chan int)<br> go func() {<br>  select {<br>  case val := &lt;-ch:<br>   fmt.Println(val)<br>  case &lt;-ctx.Done():<br>   fmt.Println(&quot;Cancelled, goroutine exiting gracefully&quot;)<br>   return<br>  }<br> }()<br>}</pre><p>Now the goroutine has an exit door. Every goroutine should have an exit door. This is basically fire-safety code for concurrency.</p><h3><strong>Chapter 7: Worker Pools — Because Ten Thousand Goroutines Is a Little Much</strong></h3><pre>func worker(id int, jobs &lt;-chan int, results chan&lt;- int) {<br> for j := range jobs {<br>  fmt.Printf(&quot;Worker %d processing job %d\n&quot;, id, j)<br>  time.Sleep(time.Millisecond * 200)<br>  results &lt;- j * 2<br> }<br>}<br><br>func main() {<br> jobs := make(chan int, 100)<br> results := make(chan int, 100)<br><br> for w := 1; w &lt;= 3; w++ {<br>  go worker(w, jobs, results)<br> }<br><br> for j := 1; j &lt;= 9; j++ {<br>  jobs &lt;- j<br> }<br> close(jobs)<br><br> for a := 1; a &lt;= 9; a++ {<br>  fmt.Println(&lt;-results)<br> }<br>}</pre><p>Three workers, nine jobs, one channel doling out work like a foreman handing out clipboards. close(jobs) tells the workers “that’s all, folks” — a range over a closed channel simply finishes once it’s drained, no explicit “please stop” message required. Elegant, efficient, and deeply satisfying to watch run.</p><h3>Final Thoughts</h3><p>Concurrency in Go looks deceptively simple. Add a go keyword, create a channel, and suddenly you&#39;re running multiple things at once.</p><p>But writing concurrent programs that actually work is a different story.</p><p>Goroutines need coordination. Channels can block. Shared memory can introduce races. And forgotten goroutines can quietly become leaks.</p><p>The important thing isn’t just knowing how to launch goroutines. It’s knowing how they communicate, when they stop, and who is responsible for them.</p><p>There is still plenty more to explore in Go concurrency, but hopefully these examples have made the fundamentals a little less intimidating.</p><p>If you’ve made it this far, thanks for reading! I’d love to hear your thoughts, corrections, or suggestions.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ea825cddc075" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Follow the Pointer: Stack vs Heap]]></title>
            <link>https://medium.com/@manikurmi14/follow-the-pointer-stack-vs-heap-8b144bd3016e?source=rss-962ed77796aa------2</link>
            <guid isPermaLink="false">https://medium.com/p/8b144bd3016e</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[rust]]></category>
            <category><![CDATA[memory-management]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Pointdexter]]></dc:creator>
            <pubDate>Tue, 29 Sep 2026 19:07:27 GMT</pubDate>
            <atom:updated>2026-09-29T19:07:27.054Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uiMIu-RUh8cZ5VwbK4F7Kw.jpeg" /></figure><p><em>Note : This blog only explains the theory, how data are stored in memory or more explicitly on heap or stack! might add code examples in future, It’s a short and decent starting point to understand how things are stored.</em></p><p>Many programming languages don’t require you to think about the stack and the heap very often. But in a systems programming language C, C++ and Rust, whether a value is on the stack or the heap affects how the language behaves and why you have to make certain decisions.</p><p>Both the stack and the heap are parts of memory available to your code to use at runtime, but they are structured in different ways. The stack stores values in the order it gets them and removes the values in the opposite order. This is referred to as <em>last in, first out (LIFO)</em>. Think of a stack of plates: When you add more plates, you put them on top of the pile, and when you need a plate, you take one off the top. Adding or removing plates from the middle or bottom wouldn’t work as well! Adding data is called <em>pushing onto the stack</em>, and removing data is called <em>popping off the stack</em>. All data stored on the stack must have a known, fixed size. Data with an unknown size at compile time or a size that might change must be stored on the heap instead.</p><p>The heap is less organized: When you put data on the heap, you request a certain amount of space. The memory allocator finds an empty spot in the heap that is big enough, marks it as being in use, and returns a <em>pointer</em>, which is the address of that location. This process is called <em>allocating on the heap</em> and is sometimes abbreviated as just <em>allocating</em> (pushing values onto the stack is not considered allocating). Because the pointer to the heap is a known, fixed size, you can store the pointer on the stack, but when you want the actual data, you must follow the pointer. Think of being seated at a restaurant. When you enter, you state the number of people in your group, and the host finds an empty table that fits everyone and leads you there. If someone in your group comes late, they can ask where you’ve been seated to find you.</p><p>Pushing to the stack is faster than allocating on the heap because the allocator never has to search for a place to store new data; that location is always at the top of the stack. Comparatively, allocating space on the heap requires more work because the allocator must first find a big enough space to hold the data and then perform bookkeeping to prepare for the next allocation.</p><p>Accessing data in the heap is generally slower than accessing data on the stack because you have to follow a pointer to get there. Contemporary processors are faster if they jump around less in memory. Continuing the analogy, consider a server at a restaurant taking orders from many tables. It’s most efficient to get all the orders at one table before moving on to the next table. Taking an order from table A, then an order from table B, then one from A again, and then one from B again would be a much slower process. By the same token, a processor can usually do its job better if it works on data that’s close to other data (as it is on the stack) rather than farther away (as it can be on the heap).</p><p>When your code calls a function, the values passed into the function (including, potentially, pointers to data on the heap) and the function’s local variables get pushed onto the stack. When the function is over, those values get popped off the stack.</p><p>Keeping track of what parts of code are using what data on the heap, minimizing the amount of duplicate data on the heap, and cleaning up unused data on the heap so that you don’t run out of space.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8b144bd3016e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>