On 2012-11-19 09:31:46 +0000, "foobar" <f...@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.o...@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.for...@michelf.ca
http://michelf.ca/

Reply via email to