Похожие чаты

I have some questions : 1- what parts of go are

thread safe and what parts are not? (from parts I mean for example map , ...)

2-when to use mutexes ?
and when to use channels ?

3-what is select statement and it's usecases?

4- can we understand that code has coroutines conflicts without running go race detector command?

16 ответов

5 просмотров

1. Most things are not thread safe, if the doc doesn't say thread safe it is not 2. Try not to use mutexes. Also I don't like the name, bottlenecks is a far better name. Use channels instead wherever possible 3. Select waits (yields) until data is available or a condition is met. This is very useful when a coroutine must wait for several events 4. Yes, it will require quite an understanding of how go scheduling and coroutine system works

Masoud- Автор вопроса
Ludovic 'Archivist' Lagouardette
1. Most things are not thread safe, if the doc doe...

2- which one is better for performance and memory usage between mutex and channel? 4- I meant for example when we using a library we don't know how that library implemented (thread-safe or not) unless read the whole library code

Masoud
2- which one is better for performance and memory ...

2. generally the channel is better in its worst case and the mutex is better in its best case. This means that channels basically scale better in terms of accesses than mutexes 4. Read the doc. If the docs of a library don't say something is thread safe, it is generally advised to take it for not thread safe

1. pretty much nothing. You have to synchronize explicitly most of the time 2. when you've got mutable state shared across goroutines 3. oh, come on, you didn't pass The Tour of Go, did you? 4. no.

Ludovic 'Archivist' Lagouardette
1. Most things are not thread safe, if the doc doe...

channels don't make sense when what you've got is shared state. channels are for inter-goroutine communication

Roman Sharkov
channels don't make sense when what you've got is ...

That is the kind of moments when using goroutines as agents helps

Masoud
2- which one is better for performance and memory ...

a mutex is always way cheaper than a channel

Masoud- Автор вопроса
Roman Sharkov
1. pretty much nothing. You have to synchronize ex...

and thank you Mr.Sharkov 😊 btw your "sched" was cool

Ludovic 'Archivist' Lagouardette
That is the kind of moments when using goroutines ...

it can help in some cases, but it's always going to be wasted performance sometimes a mutex is just simpler and cheaper

Ludovic 'Archivist' Lagouardette
afaik, failing to lock a mutex is fairly expensive

a channel is built upon multiple mutexes. It's always more expensive than a mutex

Roman Sharkov
a channel is built upon multiple mutexes. It's alw...

No the channel implementation of go does not actually use mutexes

Ludovic 'Archivist' Lagouardette
No the channel implementation of go does not actua...

https://github.com/golang/go/blob/master/src/runtime/chan.go

Похожие вопросы

Обсуждают сегодня

We heading to 1.1$ 🤔?
CryptoBo$$
35
Anyone here suffers from unexplained aural migraines, who would be up for talking for a bit? Doesn't *have* to be aural, but I am not asking about headaches, I mean actual mi...
Martin Rys
55
A couple thoughts from a random internet stranger: 1. If you want this project to gain traction you cannot keep being negative. If I just came here after finding out about Kd...
Eric Wild
45
Сonst magicTgHTML = (text, entities) => { let processedText = text; let offsetShift = 0; entities.forEach(entity => { const { offset, length, type, url, ...
Андрей
1
Здравствуйте товарищи! решил всё таки поставить линукс. Порядок создание разделов /boot/efi 200МиБ; /boot 1000; подсистему / 80000; swap 8Гб Будет норм?
K2
19
Koi bata sakata hai yaha ? Is baar shot open karna theek rahega kya ?
Hakuna Matata
13
Can you help a noob? I know LTC was one of the early alt coins. But what is the benefit of it today? What are its attributes? Why should I be bullish on it this bull run?
CryptoNoobian ($PEPI)
14
How Will #Monero Be Attacked? First of all I want to tell you that this is not teaching the network attackers, the central regulators. They already know how to attack the net...
Li₿ΞʁLiøη
3
#wazirx 15 May my account has fund of rupees 10000 but 16 May my balance is showing 8200 why?? Without any withdrawal
Learnwi
12
подскажите пожалуйста, как мне освободить результат записанный в переменную result? в чем проблема подскажите если МОЖЕТЕ?
Михаил Helper
28
Карта сайта