Golang Tutorial | How To Implement Concurrency With Goroutines and Channels

preview_player
Показать описание
Golang is efficient, very efficient. Much of this efficiency is attributed to its unique abstractions when dealing with concurrency. Java fo,r example, maps its threads to OS threads, while Go uses its own goroutines scheduler to further abstract its lightweight goroutines from OS threads. In short, Golang is very frugal with how it uses OS threads; if a goroutine becomes blocked, Go’s scheduler will switch to another goroutine in its place to keep the thread busy as much as possible. Since each CPU core handles a limited number of threads (and spawning new threads is expensive), keeping these threads fed with work is a great thing indeed.

Hi Folks! I am Kavit, a software engineer with a passion for teaching.

Please follow me and show your support, so that I can keep bringing this type of content.

PLAYLISTS

Blockchain | Videos available under the Youtube channel

#golang #programming #language #install #goroutines
#channel #concurrency #concurrent

LIKE & SHARE & ACTIVATE THE BELL
Thanks For Watching :-)
Рекомендации по теме
Комментарии
Автор

I agree with what Kumat Mebrah wrote. Excellently explained.

sirslaff
Автор

Good stuff man, well explained. I love the way you say "cool"!

kumatmebrah
Автор

The checkURLs part at the end is way too complicated. WaitGroup.Wait is to wait for all threads to be finished. But you put it in another goroutine/thread, that's not the way to use it.

Just count up with Add and let threads count down with Done. When the counter reaches zero, WaitGroup.Wait will stop blocking and will let the thread that started this all go through the barrier.
After the WaitGroup you use a blocking channel to continue. That's unnessessary. The WaitGroup does it alone. It's meant for that.

wWvwvV
Автор

I see you're using the Atom editor and you're typing in all the Go imports. I guess Atom has no support for LSP (language server protocol)? LSP would add all the imports when saving. You even have code completion over not imported packages (as long they are in go.mod via 'go get').

I don't want to sound harsh but it sounds harsh. Atom, the Github editor, wont be developed any further in favor of Github codespaces and vscode. You can read it in the news.

I'm not sure if this good or bad.

wWvwvV
welcome to shbcf.ru