Something needs to happen with shared, and soon.
foobar
foo at bar.com
Mon Nov 19 01:31:46 PST 2012
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.
More information about the Digitalmars-d
mailing list