Something needs to happen with shared, and soon.

Michel Fortin michel.fortin at michelf.ca
Mon Nov 19 09:24:57 PST 2012


On 2012-11-19 09:31:46 +0000, "foobar" <foo at bar.com> said:

> On Saturday, 17 November 2012 at 13:22:23 UTC, Michel Fortin wrote:
>> On 2012-11-16 18:56:28 +0000, Dmitry Olshansky <dmitry.olsh at gmail.com> said:
>> 
>>> 11/16/2012 5:17 PM, Michel Fortin пишет:
>>>> In case you want to protect two variables (or more) with the same mutex.
>>>> For instance:
>>>> 
>>>>     Mutex m;
>>>>     synchronized(m) int next_id;
>>>>     synchronized(m) Object[int] objects_by_id;
>>>> 
>>> 
>>> Wrap in a struct and it would be even much clearer and safer.
>>> struct ObjectRepository {
>>> 	int next_id;
>>> 	Object[int] objects_by_id;
>>> }
>>> //or whatever that combination indicates anyway
>>> synchronized ObjectRepository objeRepo;
>> 
>> I guess that'd be fine too.
> 
> <snip>
> 
> That solution does not work in the general case. More specifically any 
> graph-like data structure. E.g a linked-lists, trees, etc..
> Think for example an insert to a shared AVL tree.

No solution will be foolproof in the general case unless we add new 
type modifiers to the language to prevent escaping references, 
something Walter is reluctant to do. So whatever we do with mutexes 
it'll always be a leaky abstraction. I'm not too trilled by this either.

-- 
Michel Fortin
michel.fortin at michelf.ca
http://michelf.ca/



More information about the Digitalmars-d mailing list