8000 proposal: thread-local or per-cpu storage support · Issue #22476 · golang/go · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

proposal: thread-local or per-cpu storage support #22476

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
idealvin opened this issue Oct 28, 2017 · 9 comments
Closed

proposal: thread-local or per-cpu storage support #22476

idealvin opened this issue Oct 28, 2017 · 9 comments

Comments

@idealvin
Copy link

Use case:
Write a service using Thrift framework. Thrift may have several logical threads or routines to handle request from clients.

In my implementation of the service, all the thrift logical threads will finally call my function:
function do_something()
And the function do_something will read data from redis server. With thread-local support, I can create a connection to the redis server for each thread.

This is very useful and I don't know how to implement it without thread-local storage support. So please consider about it. Thanks.

@gopherbot gopherbot added this to the Proposal milestone Oct 28, 2017
@dlsniper
Copy link
Contributor

This is very useful and I don't know how to implement it without thread-local storage support. So please consider about it. Thanks.

The problem seems to be the implementation, not the language. Please reconsider your problem and refactor the implementation by avoiding any prior form of knowledge about TLS. At that point the implementation will reveal itself as a simple, obvious, solution based on existing concepts and tools.

tl;dr: don't Write C++/Java in Go, write Go in Go.

@idealvin
Copy link
Author

@dlsniper
Yeah, I have just turned from C++ to Go recently and not familiar with Go.

In my case, it seems that I have no better solution with Thrift as the logical threads are created and
scheduled by Thrift itself.

Is there some existing solutions for my case? Thanks very much.

@ALTree
Copy link
Member
ALTree commented Oct 28, 2017

Dup of the old #8281

@dlsniper
Copy link
Contributor

As this is not a Go issue I think we should move it in one of the following mediums:

I'm sure you'll find a way to solve this.

I believe this should be closed.

@idealvin
Copy link
Author

Last question. Thanks.
Why not provide a function to get the current routine id in go?

@dlsniper
Copy link
Contributor

Because in 4.5 years of writing concurrent Go I've never needed such functionality and, for the most part, neither will the vast majority of the programmers. There are extensive, similar, threads out there proving over and over again that this is not a needed feature in order to write concurrent applications. Please use the available search solutions to find them in the above mentioned spaces.

To ask the similar question: Given solutions exist outside of this particular design, why not use a different algorithm instead of requiring a change of the standard library to allow for a very specific implementation to exist?

@idealvin
Copy link
Author

@dlsniper
Yes, I think I have found a solution like this:

I write a new redis client with n(cpu num) routines and one connection per routine. The n routines will handle redis tasks together. I just send a task to the redis client and wait for the result.

Thanks.

By the way, your golang-plugin for ideaide seems not work on pycharm 2017.2 now. I really like this plugin!

@dlsniper
Copy link
Contributor

By the way, your golang-plugin for ideaide seems not work on pycharm 2017.2 now. I really like this plugin!

Please use Gogland (dedicated Go IDE) or IntelliJ IDEA Ultimate. For additional information ping me on Gophers Slack or Twitter.

@idealvin
Copy link
Author

@dlsniper ok, thanks!

@golang golang locked and limited conversation to collaborators Oct 28, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants
0