aspects on methods?
I want to use aspect-like annotations to transform @Lockable class Abc { @sync void f() { writeln("f"); } @shared void g() { writeln("g"); } } to something like: class Abc { shared(ReadWriteMutex) _lock123; this() { _lock123 = cast(shared)(new ReadWriteMutex()); } void f() { synchronized((cast()_lock123).writer) { writeln("f"); } } void g() { synchronized((cast()_lock123).reader) { writeln("g"); } } } How can I do that?
some atomic structs
I wrote some java-like atomic structs. Please criticize it https://dpaste.dzfl.pl/24f1438ebb52
thread-safe shared field access
For example I have a shared from different threads variable. What piece of code is correctly thread-safe? First: shared class A { shared(int) x; void test1() { x = 10; x += 5 writeln(x); } } Or second: import core.atomic; shared class A { shared(int) x; void test1() { atomicStore(x, 10); atomicOp!("+=")(x, 5); writeln(atomicLoad(x)); } }
Re: compilation error with shared ReadWriteMutex
On Thursday, 30 June 2016 at 12:25:54 UTC, Steven Schveighoffer wrote: On 6/30/16 8:18 AM, jj75607 wrote: [...] You don't need to mark this shared, because the entire class is shared, all members are implicitly marked shared. [...] Thanks! Is this a compilation only 'cast' with no runtime works?
Re: opEquals on shared object
On Thursday, 30 June 2016 at 12:21:03 UTC, Steven Schveighoffer wrote: On 6/30/16 6:26 AM, jj75607 wrote: Hello! I need to overload opEquals on shared class C shared class C { override bool opEquals(Object o) { return false; } } But compilation fails with the message: Error: function f700.C.opEquals does not override any function, did you mean to override 'object.Object.opEquals'? What am I doing wrong? Object.opEquals is not marked shared. You can't override a non-shared method with a shared one. You need to remove override. But... unfortunately, this may not work in practice. The opEquals handling for objects is pretty much screwed unless you have unshared mutable objects. I think it may work for const objects, but not in a good way. -Steve Thanks! But what should I do to fix that code? shared class C { bool opEquals(Object o) { return false; } } class A(T) { void f(T a, T b) { if(a == b) writeln("equals"); else writeln("non equals"); } } int main(string[] argv) { auto a1 = new A!int; a1.f(1,2); auto a2 = new A!(shared(C)); shared C c = new shared(C); a2.f(c,c); return 0; } It fails with Error: none of the overloads of 'opEquals' are callable using argument types (shared(C), shared(C))
compilation error with shared ReadWriteMutex
I wrote shared class with rwmutex import core.sync.rwmutex; shared class Shared { ReadWriteMutex rwmutex; int[] items; this() { rwmutex = new ReadWriteMutex(); } } But it fails with: Error: cannot implicitly convert expression (new ReadWriteMutex(cast(Policy)1)) of type core.sync.rwmutex.ReadWriteMutex to shared(ReadWriteMutex) I add `shared' keyword to the `rwmutex' variable shared class Shared { shared(ReadWriteMutex) rwmutex; int[] items; this() { rwmutex = new shared(ReadWriteMutex)(); } } And got another compilation error: Error: non-shared method core.sync.rwmutex.ReadWriteMutex.this is not callable using a shared object How can I use shared class with mutex correctly?
opEquals on shared object
Hello! I need to overload opEquals on shared class C shared class C { override bool opEquals(Object o) { return false; } } But compilation fails with the message: Error: function f700.C.opEquals does not override any function, did you mean to override 'object.Object.opEquals'? What am I doing wrong?
Re: multithreading profiling
On Monday, 18 April 2016 at 13:45:20 UTC, Marc Schütz wrote: Which platform/OS, dmd version, and command line are you using? Windows7, DMD 2.071.0, run from Visual Studio 2013 Community + VisualD 0.3.43
multithreading profiling
Hello! Is it possible to start profiling on multithreaded app with Dmd? https://issues.dlang.org/show_bug.cgi?id=14511 is open. I am doing wrong or why this program segfaults if compiled with profiler hooks? import core.atomic; shared struct S { uint counter; bool inc() shared { atomicOp!("+=")(counter, 1); return true; } } int main(string[] argv) { S s; return 0; } Thank you!