Issue I am trying to get a better understanding of the definition preemptive and cooperative in the context of Go. Wiki states for preemptive multitasking In computing, preemption is the act of temporarily interrupting an executing task, with the intention
Continue readingTag: multithreading
Why are there more OS threads when running go simple app?
Issue When running a simple app, there are more OS threads than the max allowed by my processor. This is the sample code: package main import ( "fmt" "runtime" "time" ) func doSomething() { time.Sleep(10 * time.Minute) } func main()
Continue readingBest way to wake 0-N sleeping goroutines at once
Issue I’m writing a program where I start N (N is a command-line argument) worker threads, and at any time 0 to N-1 of them can be waiting on another to update a variable. What’s the best way for the
Continue readingPeterson's algorithm and deadlock
Issue I am trying to experiment with some mutual execution algorithms. I have implemented the Peterson’s algorithm. It prints the correct counter value but sometimes it seems just like some kind of a deadlock had occurred which stalls the execution
Continue readingHow to find the number of threads waiting for mutex lock in Sync.Mutex?
Issue I am using this in a go subroutine a.Lock() … enter code here … a.Unlock() Is there any api to know how many threads are waiting at a.Lock()? Solution Is there any api to know how many threads are
Continue readingUsing a GoLang Routine to Return to Multiple Threads
Issue I am building an API that can queue up requests to GET an external website and subsequently perform some work by interacting with that API. I am trying to figure out how to avoid duplicate simultaneous go routines. That
Continue readingWhy does my program not shut down when I use goroutine in main?
Issue Context Please, read the comments in code carefully. Everything is in them. In case you have experience using discordgo The full code can be found here: https://github.com/telephrag/kubinka/tree/bug (see packages strg and main) With addition of goroutine command handlers stop
Continue readingGoroutines – send critical data to the single goroutine and wait for result
Issue I have many goroutines running in my application, and I have another goroutine that must handle only one request at the same period of time and then send the result back to caller. It means other goroutines should wait
Continue readingWhen will Go scheduler create a new M and P?
Issue Just learned golang GMP model, now I understand how goroutines, OS threads, and golang contexts/processors cooperate with each other. But I still don’t understand when will an M and P be created? For example, I have a test code
Continue readingLoad data from reading files during startup and then process new files and clear old state from the map
Issue I am working on a project where during startup I need to read certain files and store it in memory in a map and then periodically look for new files if there are any and then replace whatever I
Continue reading