January 17, 2013
On 17.1.2013 12:56, Maxim Fomin wrote:
> Casting away shared in undefined behavior. Although it may be not written explicitly in dlang.org, once D will have a standard like C or C++, it will be name like so.
> 
> In practice this means that behavior of program is uncertain and may
> result in many consequences. In this case content of arrays may be any
> of 1,2,3,4,5,6.
> ... snip ...
> Note, if you mark functions as @safe, the code will not compile, because
> throwing shared is not allowed in D safe code.

I know about some peculiarities of shared (this thread http://forum.dlang.org/thread/k7orpj$1tt5$1@digitalmars.com was a good eye-opener) and tend to avoid it as much as possible and solve my problems with message passing concurrency, however there are some times when I had to do some casting and just be careful.

>> What happens when you cast from and to shared? Is there any moving in memory from TLS and back? Or does it just access the memory as if it were in shared space?
> 
> It is implementation specific, but I guess nothing is moved, just a variable is reinterpreted.

Ok, good.

> ... snip ...
> You can compile this code and look at addresses and assembly if you are
> interested in implementation details.

Good ol' printf. I should have thought about it. Thanks.

Martin
1 2
Next ›   Last »