asynkron / protoactor-go

Proto Actor - Ultra fast distributed actors for Go, C# and Java/Kotlin
http://proto.actor
Apache License 2.0
5k stars 518 forks source link

Go coroutine thread safe #1039

Closed molixiaoge closed 4 months ago

molixiaoge commented 5 months ago

Hi, i run the example actor-helloworld.The func Receive(context actor.Context) {} called with different coroutine ,so I test concurrency map write,it work well.I want to know how it do work thread safe with differenct gocourines?

rogeralsing commented 4 months ago

Yes, that is the whole point of it. When there are one or more messages in the mailbox, the actor is scheduled on a goroutine. Once the mailbox is empty, it goes back to idle, and the goroutine is released. Once a new message arrives again, it is yet again scheduled onto a goroutine (a new one)

But there are never ever more than one goroutine running for a given actor

molixiaoge commented 4 months ago

Thx . I understand now.