On 29 October 2010 17:06, James Carman <[email protected]> wrote:
> On Fri, Oct 29, 2010 at 11:40 AM, sebb <[email protected]> wrote:
>>
>> If Config instances are immutable, then there is no need to synch.
>> access to their contents.
>> However, if the field which stores the Config instance is not final,
>> then all accesses to that need to be synch. - or the field could be
>> volatile.
>>
>> Once the code has obtained the config pointer safely, it can access
>> the final Config fields without synch. This would eliminate the need
>> for the locks, provided that the config instance was fetched at most
>> once per operation.
>>
>
> If the only place where that field can change is in the reconfigure()
> method, then you can use the read/write lock to handle your
> synchronization.

Yes, but the code will still need to use the read lock whenever it
reads the field to ensure changes are propagated correctly.
Both the writer and reader threads need to synch. on the same lock in
order for changes to be published safely.

Not sure using a read/write lock would gain anything over using
volatile - which has the advantage that one cannot bypass it.

> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to