Похожие чаты

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 ответов

18 просмотров

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

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

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

Господа, а что сейчас вообще с рынком труда на делфи происходит? Какова ситуация?
Rꙮman Yankꙮvsky
29
А вообще, что может смущать в самой Julia - бы сказал, что нет единого стандартного подхода по многим моментам, поэтому многое выглядит как "хаки" и произвол. Короче говоря, с...
Viktor G.
2
@Benzenoid can you tell me the easiest, and safest way to bu.y HEX now?
Živa Žena
20
This is a question from my wife who make a fortune with memes 😂😂 About the Migration and Tokens: 1. How will the old tokens be migrated to the new $LGCYX network? What is th...
🍿 °anton°
2
30500 за редактор? )
Владимир
47
а через ESC-код ?
Alexey Kulakov
29
What is the Dex situation? Agora team started with the Pnetwork for their dex which helped them both with integration. It’s completed but as you can see from the Pnetwork ann...
Ben
1
Гайс, вопрос для разносторонее развитых: читаю стрим с юарта, нада выделять с него фреймы с определенной структурой, если ли чо готовое, или долбаться с ринг буффером? нада у...
Vitaly
9
Anyone knows where there are some instructions or discort about failed bridge transactions ?
Jochem
21
@lozuk how do I get my phex copies of my ehex from a atomic wallet, to move to my rabby?
Justfrontin 👀
11
Карта сайта