[rust-dev] Shared 2 Owned

Steven Blenkinsop steven099 at gmail.com
Tue Apr 23 14:18:53 PDT 2013


The only alternative I can think of is to really twist up the notion of
lifetimes/regions to enforce correctness. For example, regions could be
added to shared pointers, and then two tasks could rendezvous with both of
their heaps being accessible, with the type system ensuring that tasks
don't end up with references into each other's heaps. Plausibly, you could
then create owned "task" values which you could pass between tasks, whose
sole purpose was to encapsulate the shared pointers belonging to one of
these regions.

But this is stretching the notion of lifetimes a bit far.


On Tue, Apr 23, 2013 at 9:54 AM, Alexander Stavonin <a.stavonin at gmail.com>wrote:

> Felix, thank you for response. I agree with you about difference between
> Shared and Owned memory models. It's two different heaps
> with different management rules. It's clean. Now, lets go
> to practical things such as next one. We have two Tasks with some
> computations. For passing values between the tasks we have use Owned box
> but, internally, we usually are using Shared boxes. In this case, for all
> tasks we have to write converters from Shared to Owned and
> from Owned to Shared boxes. It's really big source code overhead from
> nothing.
>
> Regards,
> Alex.
>
>
> 2013/4/23 Felix S. Klock II <pnkfelix at mozilla.com>
>
> Alexander-
>>
>> What are you suggesting would be the semantics for a Shared -> Owned
>> conversion?
>>
>> Just think about it in the the abstract for a moment: If X and Y are both
>> sharing a reference to a @Pizza, and X decides it wants to hand the pizza
>> to a customer who is expecting a ~Pizza, what is X supposed to do?  Block
>> until Y relinquishes its hold on the pizza?  To my mind, X has no choice
>> but to cook another pizza that looks just like the one it is shared with Y.
>>
>> (Now, Owned -> Shared conversion might actually make sense in the
>> abstract; at that point I think we'd just be encountering implementation
>> artifacts of the Rust language, rather than fundamental obstacles?)
>>
>> Cheers,
>> -Felix
>>
>>
>> On Tue Apr 23 15:36:25 2013, Alexander Stavonin wrote:
>>
>>> Hi all, I'm really confused. What's about Shared 2 Owned conversions?
>>> This one looks ugly, nevertheless works:
>>>
>>> let a = @5;
>>> let b = *a;
>>> let c = ~b;
>>> io::println(fmt!("%?, %?, %?", a, b, c));
>>>
>>> > @5, 5, ~5
>>>
>>> But what about arrays?
>>>
>>> let a = @[5];
>>> let b = *a;
>>> let c = ~b;
>>>
>>> > error: type @[<VI0>] cannot be dereferenced
>>>
>>> Is it true, that there is no any way for converting between different
>>> boxes types without deep copying of objects?! I'm shocked %)
>>>
>>>
>>> ______________________________**_________________
>>> Rust-dev mailing list
>>> Rust-dev at mozilla.org
>>> https://mail.mozilla.org/**listinfo/rust-dev<https://mail.mozilla.org/listinfo/rust-dev>
>>>
>>
>>
>>
>> --
>> irc: pnkfelix on irc.mozilla.org
>> email: {fklock, pnkfelix}@mozilla.org
>>
>>
>
> _______________________________________________
> Rust-dev mailing list
> Rust-dev at mozilla.org
> https://mail.mozilla.org/listinfo/rust-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/rust-dev/attachments/20130423/1071d6e2/attachment.html>


More information about the Rust-dev mailing list