Am 14.11.2012 12:00, schrieb Walter Bright:
On 11/14/2012 2:49 AM, Benjamin Thaut wrote:
Am 14.11.2012 11:42, schrieb Walter Bright:
On 11/14/2012 1:23 AM, Benjamin Thaut wrote:
Could you please give an example where it would break?

Thread 1:
   1. create shared object
   2. pass reference to that object to Thread 2
   3. destroy object

Thread 2:
   1. manipulate that object


But for passing a reference to a value type you would have to use a
pointer,
correct? And pointers are a unsafe feature anyway...
I don't see your point.

Pointers are safe. It's pointer arithmetic that is not (and escaping
pointers).


And if the use of pointers is allowed, I can make the same case break
in a
single threaded environment without shared.

1. You can't escape pointers in safe code (well, it's a bug if you do).

2. If the struct is on the heap, it is only destructed if there are no
references to it in any thread. If it is not on the heap, and you are in
safe code, it should always be destructed safely when it goes out of scope.

This is not so for shared pointers.

So just to be clear, escaping pointers in a single threaded context is a bug. But if you escape them in a multithreaded context its ok?
That sounds inconsistent to me.

But if that is by design your argument is valid.

I still can not think of any real world usecase though where this could actually be used.

A small code example which would break as soon as we allow destructing of shared value types would really be nice. (maybe even in the langauge documentation, because I coudln't find anything)

Kind Regards
Benjamin Thaut

Reply via email to