August 17, 2017
On Wednesday, 16 August 2017 at 23:15:10 UTC, crimaniak wrote:
> I wonder if it possible and usable to make some template to support this pattern, where we give mutex(es), shared object(s) and delegate to operate with objects as non-shared.

https://dpaste.dzfl.pl/8b3b05c8ec0a like this? Not sure if it helps, don't forget that it's a casted shared object.
August 17, 2017
On 8/17/17 8:41 AM, Kagamin wrote:
> On Wednesday, 16 August 2017 at 13:14:55 UTC, Steven Schveighoffer wrote:
>> But that isn't a concern for Variant. It is only calling the postblit, which does work.
> 
> Shouldn't it call destructor when it goes out of scope?

You're right, and it does. It uses the typeid to destroy it, which I think ignores any attributes.

I've updated my PR to switch to the __xdtor method, which takes into account attributes of the method.

This doesn't suffer from the same incorrect assumption the compiler makes when destroying something in a scope, so ironically, using a Variant to wrap a shared type with a destructor is going to work better than using the stack :)

-Steve
August 21, 2017
On Thursday, 17 August 2017 at 13:09:29 UTC, Kagamin wrote:
> On Wednesday, 16 August 2017 at 23:15:10 UTC, crimaniak wrote:
>> I wonder if it possible and usable to make some template to support this pattern, where we give mutex(es), shared object(s) and delegate to operate with objects as non-shared.
>
> https://dpaste.dzfl.pl/8b3b05c8ec0a like this? Not sure if it helps, don't forget that it's a casted shared object.
 Yes, something like this. In general, I thought about the possibility of using several shared objects in this block but then realized that everything can be reduced to the case of one object.

August 21, 2017
On Monday, 14 August 2017 at 03:59:48 UTC, Jonathan M Davis wrote:

> And no, this isn't ideal, but the only semi-decent solution that's been proposed that safely casts away shared for you is synchronized classes, which Andrei describes in TDPL but have never been implemented.
 After reading this I did some experiment to understand the situation better. I make a simple class and unittest:

// dmd sync1.d -unittest -main

unittest
{
    import std.stdio;

synchronized
class A
{
    private int a;

    void inc()
    {
	++a;
    }

    int get(){ return a;}
}

    shared A a;

    for(int i=0; i<100; ++i)
	a.inc();
	
    writeln(a.get);	

}

Oops! Deprecation: read-modify-write operations are not allowed for shared variables. Use core.atomic.atomicOp!"+="(this.a, 1) instead.

Why use atomic operations if the class already synchronized? Well..

...
   import core.atomic: atomicOp;
...
	// ++a; // Deprecation: read-modify-write operations are not allowed for shared variables. Use core.atomic.atomicOp!"+="(this.a, 1) instead.
	atomicOp!"+="(this.a, 1);
...

ok, works. But it works by the way as if synchronized just makes all methods shared, but does not provide the object methods with a mutex lock, as Java does. Am I right here? And what preventing to implement it right, lack of manpower or some ideologic problems?

August 21, 2017
On Monday, 21 August 2017 at 02:17:57 UTC, crimaniak wrote:
...
>     shared A a;
...
 Sorry, accidental delete, read this as shared A a = new shared(A);

August 21, 2017
On 8/16/17 11:23 AM, Steven Schveighoffer wrote:
> On 8/16/17 8:58 AM, Steven Schveighoffer wrote:
>> However, I have found a better way to call postblit that involves the qualifiers than the way Variant currently does it. I'm going to submit a PR to fix these issues.
> 
> https://github.com/dlang/phobos/pull/5694

This has been merged, so you should now be able to send shared types properly through send/receive on master dmd. Don't think it made it into 2.076 beta though.

-Steve
August 22, 2017
https://issues.dlang.org/show_bug.cgi?id=6585 is this fixed too? How various opIndex will behave now?
August 22, 2017
On 8/22/17 12:15 PM, Kagamin wrote:
> https://issues.dlang.org/show_bug.cgi?id=6585 is this fixed too? How various opIndex will behave now?

Seems to work. I closed as a duplicate.

-Steve
August 22, 2017
On Monday, 21 August 2017 at 18:50:50 UTC, Steven Schveighoffer wrote:
> On 8/16/17 11:23 AM, Steven Schveighoffer wrote:
>> On 8/16/17 8:58 AM, Steven Schveighoffer wrote:
>>> However, I have found a better way to call postblit that involves the qualifiers than the way Variant currently does it. I'm going to submit a PR to fix these issues.
>> 
>> https://github.com/dlang/phobos/pull/5694
>
> This has been merged, so you should now be able to send shared types properly through send/receive on master dmd. Don't think it made it into 2.076 beta though.
>
> -Steve

Great!

Thanks.

Arek
1 2 3 4
Next ›   Last »