concurrency - Immutable collection (an example in book of scala in depth) -


in book, has following example, sync insert, didn't sync lookup.i knew currentindex point different object after insert, operation of pointing different object atomic? example, suppose pointer of 8 bytes (on 64 bit machine), @ point currentindex switch pointer, if switch not atomic, such first switch first 4 bytes, , switch second 4 bytes, , if between first , second switch, lookup data, pointer points object never exists , cause problem

class immutableservice[key, value] extends service[key, value] {    var currentindex = new immutablehashmap[key,value]    def lookup(k: key): option[value] = currentindex.get(k)    def insert(k: key, v: value): unit = synchronized {        currentindex = currentindex + ((k, v))    } } 

yes, currentindex reference - changes done atomically.

check:

are 64 bit assignments in java atomic on 32 bit machine?


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -