On Thu, 13 Mar 2014 15:00:20 GMT, Etienne Cimon wrote:
On Thu, 13 Mar 2014 09:02:14 +0100, Sönke Ludwig wrote:
Am 13.03.2014 01:34, schrieb Etienne Cimon:
On Wed, 12 Mar 2014 22:50:03 +0100, Sönke Ludwig wrote:
If you ever have a situation where you are certain that it is safe to
pass some data to another thread, you can also usecast(immutable)
orcast(shared)
to talk the compiler into accepting it, but of course
this is unsafe and not recommended practice.Do you think casting a struct as immutable would perform better than using makeIsolated on a class however? (I never managed to make a struct isolated)
I forgot about isolated, so yes that may be a better choice than
shared
, if applicable. For pointers tostruct
, you can useassumeIsolated
for now, but I'll also adjustmakeIsolated
to work
for structs.So I tried
assumeIsolated
on a struct pointer as aimmutable(Struct)*
, after a lot of trial and error I guess I can report on the general behavior.First, it fails at
private string isolatedAggregateMethodsString(T)()
complaining that there's no members to loop from inforeach( mname; __traits(allMembers, T) )
, I had to addstatic if( __traits(compiles, __traits(allMembers, T)) )
before the loop to get past that.Then, it returns an IsolatedRef!(immutable(Struct)**) which doesn't pass the
static assert(isWeaklyIsolated!(FieldTypeTuple!T))
inprivate struct IsolatedRef(T)
. So I removed that assert.Finally, when I try to send it, it'll take another pointer from it and my types become conflictual with
unsafeGet
.I'll just keep on moving isolated classes for now :-P
Should work now with 3d8bbb1. But always beware of the issue that destructors are never called for GC allocated structs.