我正在看grpc的教程 https://grpc.io/docs/tutorials/basic/go.html
grpc 一元调用看起来像这样
conn, err := grpc.Dial(*serverAddr)
if err != nil {
...
}
defer conn.Close()
client := pb.NewRouteGuideClient(conn)
feature, err := client.GetFeature(context.Background(), &pb.Point{409146138, -746188906})
if err != nil {
...
}
我想知道我是否打电话
client.GetFeature
来自多个线程,它是线程安全的吗?
最佳答案
调查此 issue你可以了解到:
@rubenv asks:
Can I use a client from different threads in parallel?
@iamqizhao replies:
On client, if you want to perform multiple rpc in parallel, you should spawn multiple goroutines to do that since the rpc is synchronous/blocking
答案是肯定的,但是不能共享流 ( source )。
@trevorgray, these kinds of concurrency topics are apparently still not documented, per #682.
关于go - grpc 生成的 stub 线程安全吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49662965/