Dear all,
I'm wondering why the code in [1] is not working as expected. Expected
means getting back a map with 100 keys.
Instead I get a random number of keys which denotes the fact (proved by
tracing) that the map in store is updated concurrently without
respecting the lock annotations.
Is there a way to obtain synchronized access to key/values of the
default store?
Thank you.
Kind regards,
Marco.
[1]
declare %updating %basex:lock('CONFIG') function local:write($k as
xs:string) {
store:put("config", map:put(store:get("config"), $k, random:integer(10)))
};
let $s1 := store:put("config", map{})
let $s2 := xquery:fork-join(for $i in (1 to 100) return function(){
local:write("key" || $i) })
return count(map:keys(store:get("config")))