-
-
Notifications
You must be signed in to change notification settings - Fork 743
fix issue 10165 - No syntax to create thread-local shared variables #1302
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
Conversation
http://d.puremagic.com/issues/show_bug.cgi?id=10165 The new `std.typecons.Shared` allows the declaration of thread-local shared variables: ```D static class Foo { static shared(Foo) a; static Shared!Foo b; } //Initialize both a and b in another thread: auto thread = new core.thread.Thread({ Foo.a = new shared(Foo)(); Foo.b = new shared(Foo)(); }); thread.start(); thread.join(); //a is static shared, so there is one Foo.a for all threads. assert(Foo.a !is null); //b is just static, so this thread has a different Foo.a. assert(Foo.b is null); ```
This seems like a language issue. @9rnsr what are your thoughts about this? |
@andralex @yebblies @MartinNowak Concurrency guys make your move here. |
A thread-local variable is head unshared. So what you're trying to get is Rebindable for |
We need to fix that damn tail-const-class problem. |
AIUI this would also help porting D1 or (porting/wrapping) C++ code to D2, no? |
I sure wouldn't want to port any C++ code that uses const heavily to D at the moment. |
You're lucky DMD-FE barely uses it. :P |
I would rather have removed that than macros, although it might have been a harder sell. |
This needs to be implemented as a general solution - as mentioned by @MartinNowak there are too many similarities to Unless @idanarye wants to do anything with it I am going to close it as soon as get my hands to replacement PR. |
@Dicebot Rebindable seems much more complex than |
With tiny tweak to static if condition this works as desired: static class Foo
{
static shared(Foo) a;
static Rebindable!(shared Foo) b;
}
void main()
{
auto thread = new core.thread.Thread({
Foo.a = new shared(Foo)();
Foo.b = new shared(Foo)();
});
thread.start();
thread.join();
assert(Foo.a !is null);
assert(Foo.b is null);
} Only problem is that current name (Rebindable) is too specific and backwards-compatibility demands exactly same semantics. I propose adding new |
Have added competing PR. |
I'm closing this PR in favor of #2342 |
Fix issue 10165 (rework of PR #1302)
http://d.puremagic.com/issues/show_bug.cgi?id=10165
The new
std.typecons.Shared
allows the declaration of thread-localshared variables:
This is a problem I encountered while designing the
shared
version of the low lock singleton for mystd.idioms
library - there is some forum discussion about it here: http://forum.dlang.org/thread/fofbrlqruxbevnxchxdp@forum.dlang.org?page=5#post-knnqp6:242l7h:241:40digitalmars.com