[erlang-questions] Re: Shared/Hybrid Heap

Richard O'Keefe ok@REDACTED
Thu Oct 14 23:09:01 CEST 2010


On 14/10/2010, at 7:56 PM, Morten Krogh wrote:

> On 10/14/10 3:21 AM, Richard O'Keefe wrote:
>> On 13/10/2010, at 11:24 PM, Morten Krogh wrote:
>>> Erlang processes should have internal threads.
>>> 
>>> The programmer decides between spawning a process or a thread. Processes share almost nothing, threads almost everything.
>>> 
>> There is a tacit assumption here that if thread T1 has data structures D1 and D2
>> and it wants to share data structure D1 with thread T2, it wants to share D2 as
>> well.  This is not obviously the case.
>> 
>> 
> 
> Not as I see it. T2 doesn't need to even know about D2.

"Threads share almost everything".
> 
> The program goes like
> 
> T1 is working with D1 and D2
> ...
> _T2 = spawn_thread(init_function_t2, [D1]),
> ...
> 
> now T1 and T2 are executing in parallel. T2 doesn't even know D2.\

But "threads share almost everything".  T2 may not KNOW it's sharing
D2 with T1, but D2 is *there* in its address space.  That's a price.
Why should T2 be forced to include D2 in its address space if it
doesn't want it?

A conceptually simpler scheme is a hybrid one,
where some terms are private and some are shared,
and
	send_shared(Pid, Msg)
copies to the shared heap such parts of Msg as are not already there,
after which both the sending and the receiving process refer to the
shared version.  This gives precise control over what gets shared
and what doesn't.

It still goes very much against the spirit of Erlang, because it
wouldn't work very well if Pid referred to a process on another node.



More information about the erlang-questions mailing list